• MemberController


    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.Web.Mvc;

     

    using Teamwork.ProjectServiceReference;

     

     

    namespace Teamwork.Controllers

    {

        public class MemberController : Controller

        {

            Teamwork.ProjectServiceReference.ProjectServiceClient sv = new ProjectServiceClient();

           

            //@model IEnumerable<Teamwork.ProjectServiceReference.Member>

            public ActionResult Index()

            {

                MemberCollection mbCollection = new MemberCollection();

     

                mbCollection = sv.GetMembers();

                List<Member> ls = new List<Member>();

     

                if (mbCollection!=null && mbCollection.Count > 0)

                {

                   

                    //ls = mbCollection.ToList<Member>();

                    foreach (MyMember mymb in mbCollection )

                    {

                        ls.Add(sv.ConvertMemberToEfEntity(mymb));

                    }

                    return View(ls);

                }

     

                return View();

            }

     

            //@model Teamwork.ProjectServiceReference.Member

            public ActionResult Detail(int id)

            {

                Member mb = sv.GetMemberById(id);

                return View(mb);

            }

     

            //@model Teamwork.ProjectServiceReference.MyMember

            public ActionResult Create()

            {

                return View();

            }

     

            [HttpPost]

            //@model Teamwork.ProjectServiceReference.MyMember

            public ActionResult Create(MyMember mymb )

            {

                int iReturn = -1;

                try

                {

                    // TODO: Add insert logic here

                    if (mymb != null)

                    {

                        iReturn=sv.CreateMember(mymb);

                    }

     

                    if (iReturn == 1)

                    {

                        return View("Created");

                    }

                    else

                    {

                        return RedirectToAction("Index");

                    }

                

                }

                catch

                {

                    return View();

                }

           }//Create

     

            //@model Teamwork.ProjectServiceReference.MyMember

            public ActionResult Edit(int id)

            {

                Member member = sv.GetMemberById(id);

                MyMember mymb = sv.ConvertMemberToWcfEntity(member);

            

                ViewBag.Projects = sv.GetMemberProjects(member.LoginName);

                return View(mymb);

            

            }

          

            [HttpPost]

            //@model Teamwork.ProjectServiceReference.MyMember

            public ActionResult Edit(int id, FormCollection collection)

            {

                try

                {

                    // TODO: Add update logic here

                    Member mb = sv.GetMemberById(id);

                    mb.LoginName = collection["LoginName"];        

                    mb.Name = collection["Name"];      

                    MyMember mymb = sv.ConvertMemberToWcfEntity(mb);

              

                    int iReturn = sv.UpdateMember(mymb);

                    if (iReturn == 1)

                    {

                        ViewBag.Projects = sv.GetMemberProjects(mb.LoginName);//added by dd,2011-07-27

                        return View("Edited");

                    }

                    else

                    {

                        return RedirectToAction("Index");

                    }            

                }

                catch

                {

                    return View("Index");

                }

            }//Edit

     

            //@model Teamwork.ProjectServiceReference.Member

            public ActionResult Delete(int id)

            {

               Member mb = sv.GetMemberById(id);

                return View(mb);

            }

     

            [HttpPost]

           // @model Teamwork.ProjectServiceReference.Member

            public ActionResult Delete(int id, FormCollection collection)

            {

                int iReturn=-1;

                try

                {

                    // TODO: Add delete logic here

                    if (id > 0)

                    {

                        iReturn = sv.DeleteMemberById(id);

                    }

                    if (iReturn == 1)

                    {

                        return View("Deleted");

                    }

                    else

                    {

                        return RedirectToAction("Index");

                    }

                }

                catch

                {

                    return View();

                }

            }//Delete

     

        }

    }

     

  • 相关阅读:
    教你如何在Drcom下使用路由器上校园网(以广东工业大学、极路由1S HC5661A为例)
    selenium跳过webdriver检测并模拟登录淘宝
    无法嵌入互操作类型“Microsoft.Office.Interop.Excel.ApplicationClass”。请改用适用的接口
    使用xib制作界面有时会出现button无法点击,解决办法
    1.开博客的第一篇
    6.关于瀑布模型
    3.Freshman阶段学习内容的确定
    7.Solution的Build、Rebuild和Clean
    4.词法结构JavaScript权威指南笔记
    8.对于.NET的初步理解和介绍
  • 原文地址:https://www.cnblogs.com/quietwalk/p/2117958.html
Copyright © 2020-2023  润新知