Esempio n. 1
0
 public ActionResult Edit(FormCollection collection)
 {
     try
     {
         // TODO: Add update logic here
         string           msg = string.Empty;
         EmpLib.CBREmpLib lb  = new EmpLib.CBREmpLib("ef");
         string           id  = string.Format("{0}_{1}", collection["LastName"], collection["FirstName"]);
         if (Convert.ToBoolean(System.Web.HttpContext.Current.Session["NewEmp"]))
         {
             msg = lb.InsertEmp(id, collection["FirstName"], collection["LastName"], collection["ddlMgrs"]);
         }
         else
         {
             msg = lb.UpdateEmp(collection["FirstName"], collection["LastName"], collection["ddlMgrs"]);
         }
         ViewData["EditMessage"] = msg;
         if (!string.IsNullOrEmpty(msg))
         {
             EmpLib.mvcEmp tmp = new EmpLib.mvcEmp();
             tmp.FirstName = collection["FirstName"];
             tmp.LastName  = collection["LastName"];
             tmp.Notes     = msg;
             SetEditData(tmp);
             return(View(tmp));
         }
         return(RedirectToAction("Search"));
     }
     catch (Exception ex)
     {
         string s = ex.Message;
         return(View());
     }
 }
Esempio n. 2
0
        private EmpLib.mvcEmp SetEditData(EmpLib.mvcEmp tmp)
        {
            List <EmpMan> emps = Helpers.FormatManager(empRepo, tmp.LastName, tmp.FirstName);

            ViewData["ddlMgrs"] = new SelectList(emps,             //items
                                                 "manid",          // datavaluefield
                                                 "manid",          // datatextfield
                                                 tmp.Manager);     // selected value
            return(tmp);
        }
Esempio n. 3
0
        public ActionResult Search(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    string fn = collection["FirstName"];
                    string ln = collection["LastName"];

                    List <Emp>    lst  = (from c in empRepo.Emps where c.FirstName == fn && c.LastName == ln select c).ToList <Emp>();
                    EmpLib.mvcEmp mEmp = null;
                    if (lst.Count() == 1)
                    {
                        Emp emp = lst[0];
                        System.Web.HttpContext.Current.Session["NewEmp"] = false;
                        mEmp           = new EmpLib.mvcEmp();
                        mEmp.FirstName = emp.FirstName;
                        mEmp.LastName  = emp.LastName;
                        mEmp.Manager   = emp.Manager;
                        mEmp.Notes     = string.Empty;
                        System.Web.HttpContext.Current.Session["Emp"] = mEmp;
                    }
                    else
                    {
                        System.Web.HttpContext.Current.Session["NewEmp"] = true;
                        mEmp           = new EmpLib.mvcEmp();
                        mEmp.FirstName = fn;
                        mEmp.LastName  = ln;
                        mEmp.Manager   = string.Empty;
                        mEmp.Notes     = string.Empty;
                        System.Web.HttpContext.Current.Session["Emp"] = mEmp;
                    }

                    return(RedirectToAction("Edit"));
                }

                return(View());
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 4
0
 public ActionResult Edit()
 {
     EmpLib.mvcEmp tmp = System.Web.HttpContext.Current.Session["Emp"] as EmpLib.mvcEmp;
     SetEditData(tmp);
     return(View(tmp));
 }