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

 

    }

}

 

 

posted @ 2011-07-27 10:34  quietwalk  阅读(308)  评论(0编辑  收藏  举报