Ejemplo n.º 1
0
        public ActionResult AddStaff(BS_Employees employee)
        {
            var code = generalCode();

            if (code == "")
            {
                return(Json(new { error = 1, msg = "can't create the staff" }, JsonRequestBehavior.AllowGet));
            }

            employee.EmployeeID = code;
            employee.IsActive   = true;

            employee.CreationDate = DateTime.Now;

            db.BS_Employees.Add(employee);

            db.SaveChanges();

            return(Json(new { error = 0, result = db.EMPLOYEE_GETBYID(code).FirstOrDefault() }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public ActionResult UpdateStaff(BS_Employees employee, string GroupId, string AccountType)
        {
            var checkStaff = db.BS_Employees.Find(employee.EmployeeID);

            if (checkStaff == null)
            {
                return(Json(new { error = 1, msg = "Infomation wrong" }, JsonRequestBehavior.AllowGet));
            }

            checkStaff.EmployeeName = employee.EmployeeName;
            checkStaff.Phone        = employee.Phone;
            checkStaff.PositionID   = employee.PositionID;
            checkStaff.PostOfficeID = employee.PostOfficeID;
            checkStaff.Email        = employee.Email;
            checkStaff.IdentifyCard = employee.IdentifyCard;

            db.Entry(checkStaff).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            if (!String.IsNullOrEmpty(checkStaff.UserLogin))
            {
                var check = db.AspNetUsers.Where(p => p.UserName == checkStaff.UserLogin).FirstOrDefault();

                if (check != null)
                {
                    check.GroupId     = GroupId;
                    check.FullName    = employee.EmployeeName;
                    check.AccountType = AccountType;

                    db.Entry(checkStaff).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }

            return(Json(new { error = 0, result = db.EMPLOYEE_GETBYID(checkStaff.EmployeeID).FirstOrDefault() }, JsonRequestBehavior.AllowGet));
        }