public ActionResult Edit(decimal id, Employee employee)
 {
     try
     {
         if (ModelState.IsValid)
         {
             Employee obj = Employee.Find(id);
             if (obj != null)
             {
                 obj = employee;
                 Employee.Update(obj);
                 ViewBag.Message = "Employee Updated Successfully";
             }
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View());
         }
     }
     catch (Exception ex)
     {
         return(View());
     }
 }
Пример #2
0
        public ContentResult Update(FormCollection form)
        {
            JObject json = new JObject();

            json["error"]   = false;
            json["message"] = "";

            if (((Employee)this.GetAccount().Profile).Department.Type == DepartmentType.HumanResources)
            {
                try
                {
                    Employee emp = (Employee) new Employee().FindProfile(Int32.Parse(form.GetValue("ID").AttemptedValue), true, true);

                    emp.Status             = (StatusType)Int32.Parse(form.GetValue("status").AttemptedValue);
                    emp.Position           = form.GetValue("position").AttemptedValue;
                    emp.Department         = new Department(Int32.Parse(form.GetValue("department").AttemptedValue), byPrimary: false);
                    emp.Code               = form.GetValue("code").AttemptedValue;
                    emp.Profile.FirstName  = form.GetValue("first-name").AttemptedValue;
                    emp.Profile.MiddleName = form.GetValue("middle-name").AttemptedValue;
                    emp.Profile.LastName   = form.GetValue("last-name").AttemptedValue;
                    emp.EmploymentDate     = DateTime.ParseExact(
                        form.GetValue("year").AttemptedValue + "-"
                        + (Int32.Parse(form.GetValue("month").AttemptedValue) + 1).ToString("00") + "-"
                        + Int32.Parse(form.GetValue("day").AttemptedValue).ToString("00"), "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    emp.Position = form.GetValue("position").AttemptedValue;

                    if (emp.Status == StatusType.Inactive)
                    {
                        emp.DateInactive = DateTime.Now;
                    }

                    emp.Update();

                    Account ac = new Account().FindByProfile(emp.Profile.ProfileID);
                    ac.Locked = Int32.Parse(form.GetValue("locked").AttemptedValue) == 2;

                    if (!ac.Exists)
                    {
                        throw new Exception("Invalid employee account was selected...");
                    }
                    ac.Update();
                }
                catch (Exception e)
                {
                    json["error"]   = true;
                    json["message"] = e.Message;
                }
            }
            else
            {
                json["error"]   = true;
                json["message"] = "You are not authorized to continue...";
            }

            return(Content(json.ToString(), "application/json"));
        }