Ejemplo n.º 1
0
        public ActionResult Create(StaffClass staffList, HttpPostedFileBase file)
        {
            if (GlobalClass.SystemSession)
            {
                ViewBag.mess = "";
                bool flag = true;
                if (string.IsNullOrEmpty(staffList.PID))
                {
                }
                else
                {
                    var uid = from x in db.StaffList where x.PID == staffList.PID && x.CompanyKey == GlobalClass.Company.CompanyKey select x;
                    if (uid.Count() > 0)
                    {
                        ViewBag.mess = "Duplicate ID";
                        flag         = false;
                    }
                    else
                    {
                    }
                }
                if (flag == true)
                {
                    if (file != null)
                    {
                        byte[] data = null;

                        data              = BufferFromImage(file, 50, 80);
                        staffList.Pic     = data;
                        staffList.PicType = file.ContentType;
                    }
                    staffList = Val.ValidateStaff(staffList, true);
                    StaffList model = new StaffList();
                    model.PersonnelKey = Guid.NewGuid();
                    model.IsUser       = true;
                    model.IsDelete     = false;
                    model.Pic          = staffList.Pic; model.PicType = staffList.PicType;
                    model.PID          = staffList.PID;
                    model.PName        = staffList.PName;
                    model.Mobile       = staffList.Mobile;
                    model.Mail         = staffList.Mail;
                    model.Designation  = staffList.Designation;
                    model.Department   = staffList.Department;
                    model.Username     = staffList.Username;
                    model.Password     = staffList.Password;
                    model.Usergr       = staffList.Usergr;
                    model.CompanyKey   = GlobalClass.Company.CompanyKey;
                    db.StaffList.Add(model);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                ViewBag.Usergr = new SelectList(db.Usergroup.Where(m => m.CompanyKey == GlobalClass.Company.CompanyKey).OrderBy(m => m.GroupName), "UserGroupKey", "GroupName", staffList.Usergr);

                return(View(staffList));
            }
            else
            {
                Exception e = new Exception("Sorry, your Session has Expired");
                return(View("Error", new HandleErrorInfo(e, "UserHome", "Logout")));
            }
        }