?Control.cs

using System;
using System.Collections.Generic;
using System.Web.Mvc;
using com.nowdocs.nowsource.Admin.BusinessLogic.SiteConfiguration;
using com.nowdocs.nowsource.Admin.ViewModels.SiteConfiguration;
using com.nowdocs.nowsource.common;
using com.nowdocs.nowsource.Models;
using log4net;

namespace com.nowdocs.nowsource.Admin.Controllers.SiteConfiguration
{
    public class SalesAdminLevelNewController : AdminController
    {
        protected static readonly ILog logger = LogManager.GetLogger("SalesAdminLevelController");

        public GroupModel CurrentGroup
        {
            get
            {
                return StateManager.CurrentGroup;
            }
            set
            {
                StateManager.CurrentGroup = value;
            }
        }

        public SalesAdminLevelNewController() : base() { }

        //
        // GET: /SalesAdminLevel/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult GetSALevelList(int id)
        {
            List<SalesAdminLevelModel> saLevelList = SalesAdminLevelBL.GetSalesAdminLevelList();

            SALevelListViewModel savm = new SALevelListViewModel();
            savm.SelectID = id;
            savm.SALevelList = new List<SALevelListItemViewModel>();

            if (saLevelList.Count > 0)
            {
                foreach (var item in saLevelList)
                {
                    SALevelListItemViewModel salm = new SALevelListItemViewModel();
                    salm.intSalesAdminLevelID = item.intSalesAdminLevelID;

                    string isActive = item.blnSalesAdminLevelActive ? "" : "(Inactive)";
                    salm.Text = (item.strSalesAdminLevelName + isActive).Trim();
                    if (salm.intSalesAdminLevelID == id)
                    {
                        salm.IsSelected = true;
                    }
                    else
                    {
                        salm.IsSelected = false;
                    }

                    savm.SALevelList.Add(salm);
                }
            }

            //ViewData["ViewEdit"] = GetViewEdit();
            ViewBag.SalesAdminLevelID = id;
            return View("SalesAdminLevelListNew", savm);
        }

        /// <summary>
        /// Display Edit View
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult EditView(UserTypeListViewModel model)
        {
            //var session = SessionManager.Current;
            CurrentGroup = null;
            if (model.ViewEdit.Equals("1"))
                return RedirectToAction("Add", new { id = 0 });
            if (model.ViewEdit.Equals("2"))
                return RedirectToAction("Edit", new { id = model.SelectID });
            if (model.ViewEdit.Equals("3"))
                return RedirectToAction("Delete", new { id = model.SelectID });
            if (model.ViewEdit.Equals("4"))
                return RedirectToAction("UpdateSalesAdminLevelActive", new { id = model.SelectID });
            return View();
        }

        #region GetViewEdit()

        public static SelectList GetViewEdit()
        {
            List<SelectListItem> item = new List<SelectListItem>();

            item.Add(new SelectListItem { Text = Resources.SalesAdminLevel.Select, Value = "0" });
            item.Add(new SelectListItem { Text = Resources.SalesAdminLevel.AddSALevel, Value = "1" });
            item.Add(new SelectListItem { Text = Resources.SalesAdminLevel.EditeSALevel, Value = "2" });
            item.Add(new SelectListItem { Text = Resources.SalesAdminLevel.DeleteSALevel, Value = "3" });
            item.Add(new SelectListItem { Text = Resources.SalesAdminLevel.ActivateOrDeactivate, Value = "4" });
            return new SelectList(item, "Value", "Text");
        }

        #endregion GetViewEdit()

        //
        // GET: /SalesAdminLevel/Create

        [HttpPost]
        [ActionName("AddSetting")]
        public ActionResult Add(SALevelListViewModel model)
        {
            SalesAdminLevelViewModel salvm = new SalesAdminLevelViewModel();
            return View(salvm);
        }

        //
        // POST: /SalesAdminLevel/Create

        [HttpPost]
        public ActionResult Add(SalesAdminLevelViewModel viewmodel)
        {
            try
            {
                SalesAdminLevelModel temp = new SalesAdminLevelModel();
                temp.strSalesAdminLevelName = viewmodel.strSalesAdminLevelName;
                if (SalesAdminLevelBL.isSalesAdminLevelRepeat(temp))
                {
                    ModelState.AddModelError("sameSALevelName", Resources.SalesAdminLevel.sameSALevelName);
                    throw new Exception();
                }
                else
                {
                    viewmodel.blnSalesAdminLevelActive = true;
                    SalesAdminLevelModel temputm = SalesAdminLevelBL.SaveSalesAdminLevel(viewmodel.ToSalesAdminLevelModel());
                }
                return RedirectToAction("Index");
            }
            catch
            {
                return View(viewmodel);
            }
        }

        //
        // GET: /SalesAdminLevel/Edit/5
        [HttpPost]
        public ActionResult Edit1(SALevelListViewModel model)
        {
            return RedirectToAction("Edit", new { id = model.SelectID });
        }

        //
        // GET: /SalesAdminLevel/Edit/5

        public ActionResult Edit(int id)
        {
            SalesAdminLevelModel utm = new SalesAdminLevelModel();
            utm.intSalesAdminLevelID = id;
            utm = SalesAdminLevelBL.GetSalesAdminLevelInfo(utm);

            SalesAdminLevelViewModel utViewModel = new SalesAdminLevelViewModel(utm);

            ViewBag.SALevelID = id;
            return View(utViewModel);
        }

        //
        // POST: /SalesAdminLevel/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, SalesAdminLevelViewModel utvm)
        {
            try
            {
                SalesAdminLevelModel temp1 = new SalesAdminLevelModel();
                temp1.strSalesAdminLevelName = utvm.strSalesAdminLevelName;
                temp1.intSalesAdminLevelID = id;
                ViewBag.SALevelID = id;
                if (SalesAdminLevelBL.isSalesAdminLevelRepeat(temp1))
                {
                    ModelState.AddModelError("sameSALevelName", Resources.SalesAdminLevel.sameSALevelName);
                    temp1 = null;
                    throw new Exception();
                }
                else
                {
                    utvm.intSalesAdminLevelID = id;
                    SalesAdminLevelModel temputm = SalesAdminLevelBL.UpdateSalesAdminLevel(utvm.ToSalesAdminLevelModel());
                }

                return RedirectToAction("index");
            }
            catch (Exception ex)
            {
                SalesAdminLevelModel userTypeModelexp = utvm.ToSalesAdminLevelModel();
                return View(new SalesAdminLevelViewModel(userTypeModelexp));
            }
        }

        //
        // GET: /SalesAdminLevel/Delete/5

        public ActionResult Delete(int id)
        {
            SalesAdminLevelModel utm = new SalesAdminLevelModel();
            utm.intSalesAdminLevelID = id;

            //utm = SalesAdminLevelBL.GetSalesAdminLevelByid(utm);

            if (utm != null)
            {
                SalesAdminLevelBL.DeleteSalesAdminLevel(utm);
            }

            return RedirectToAction("Index");
        }

        //
        // POST: /SalesAdminLevel/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, SALevelListViewModel utvm)
        {
            try
            {
                SalesAdminLevelModel temp = new SalesAdminLevelModel();
                temp.intSalesAdminLevelID = utvm.SelectID;

                if (temp != null)
                {
                    SalesAdminLevelBL.DeleteSalesAdminLevel(temp);
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View(utvm);
            }
        }

        public ActionResult UpdateSalesAdminLevelActive(int id)
        {
            SalesAdminLevelViewModel utm = new SalesAdminLevelViewModel();
            utm.intSalesAdminLevelID = id;
            SalesAdminLevelBL.UpdateSalesAdminLevelActive(utm.ToSalesAdminLevelModel());

            return RedirectToAction("index");
        }
    }
}
?
查看全文
  相关解决方案