示例#1
0
        public ActionResult Create()
        {
            var model = new EmployeeBasicInfoModel();

            this.PrepareEmployeeBasicInfoModel(model);
            return(View(model));
        }
示例#2
0
        public void BasicInfoCreate(EmployeeBasicInfoModel model, out Guid employeeId)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                var userId = this.GetCurrentUserId();

                var addr = this._repoEmployeeAddress.Insert(new mf_EmployeeAddress()
                {
                    ObjectState = ObjectState.Added,
                    address1    = model.address1,
                    address2    = model.address2,
                    address3    = model.address3,
                    countryId   = model.countryId,
                    city        = model.city,
                    postalCode  = model.postalCode,
                    updatedBy   = userId,
                });
                var _201 = this._repoEmployee201.Insert(new mf_Employee201()
                {
                    employeeCode = "-",
                    updatedBy    = userId,
                    confidential = model.confidential,
                });
                this._unitOfWork.Save();

                var emp = this._repoEmployee
                          .Insert(new mf_Employee()
                {
                    companyId         = this.GetCurrentCompanyId(),
                    firstName         = model.firstName,
                    middleName        = model.middleName,
                    lastName          = model.lastName,
                    birthDate         = model.birthDate,
                    maritalStatus     = model.maritalStatus,
                    gender            = model.gender,
                    email             = model.email,
                    contact1          = model.contact1,
                    contact2          = model.contact2,
                    contact3          = model.contact3,
                    updatedBy         = userId,
                    employeeAddressId = addr.id,
                    employee201Id     = _201.id,
                });

                this._unitOfWork.Save();
                employeeId = emp.id;
                ts.Complete();
            }
        }
示例#3
0
        public ActionResult Create(EmployeeBasicInfoModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Guid employeeId;
                    this._employeeService.BasicInfoCreate(model, out employeeId);
                    return(RedirectToAction("Edit", new { id = employeeId }));
                }
            }
            catch (Exception ex)
            {
                this.AddModelError(ex);
            }

            this.PrepareEmployeeBasicInfoModel(model);
            return(View(model));
        }
示例#4
0
 public ActionResult AjaxUpdateEmployeeBasicInfo(EmployeeBasicInfoModel model, Guid employeeId)
 {
     try
     {
         if (ModelState.IsValid)
         {
             this._employeeService.BasicInfoUpdate(employeeId, model);
         }
     }
     catch (Exception ex)
     {
         this.AddModelError(ex);
     }
     model.image = null;
     return(this.JsonResultWithModelStateInfo(data: new
     {
         extesion = model.pictureExtension,
         path = Url.Content("~/ProfilePicture/" + employeeId + model.pictureExtension + "?v=" + Guid.NewGuid()),
     }, successMsg: "Employee Basic Information successfully saved."));
 }
示例#5
0
        public void BasicInfoUpdate(Guid employeeId, EmployeeBasicInfoModel model)
        {
            var data = this._repoEmployee.Query()
                       .Include(x => x.mf_EmployeeAddress)
                       .Filter(x => x.id == employeeId).Get()
                       .FirstOrDefault();

            string serverPath = System.Web.HttpContext.Current.Server.MapPath("~/ProfilePicture");

            if (!Directory.Exists(serverPath))
            {
                Directory.CreateDirectory(serverPath);
            }

            if (model.image != null)
            {
                IDictionary <string, string> validImageFiles = new Dictionary <string, string>();
                validImageFiles.Add(".bmp", "BMP");
                validImageFiles.Add(".jpg", "Jpeg");
                validImageFiles.Add(".jpeg", "Jpeg");
                validImageFiles.Add(".gif", "GIF");

                string extenstion = Path.GetExtension(model.image.FileName);

                if (!validImageFiles.ContainsKey((extenstion ?? "").ToLower()))
                {
                    throw new Exception("Invalid File Picture");
                }

                if (File.Exists(Path.Combine(serverPath, employeeId + extenstion)))
                {
                    File.Delete(Path.Combine(serverPath, employeeId + extenstion));
                }

                model.image.SaveAs(Path.Combine(serverPath, employeeId + extenstion));

                data.pictureExtension = extenstion;
            }
            else
            {
                if (model.clearImage == "true")
                {
                    if (File.Exists(Path.Combine(serverPath, employeeId + model.pictureExtension)))
                    {
                        File.Delete(Path.Combine(serverPath, employeeId + model.pictureExtension));
                    }
                    data.pictureExtension = "";
                }
            }

            var userId = this.GetCurrentUserId();

            data.firstName     = model.firstName;
            data.lastName      = model.lastName;
            data.middleName    = model.middleName;
            data.birthDate     = model.birthDate;
            data.email         = model.email;
            data.maritalStatus = model.maritalStatus;

            data.contact1 = model.contact1;
            data.contact2 = model.contact2;
            data.contact3 = model.contact3;

            if (data.mf_EmployeeAddress == null)
            {
                data.mf_EmployeeAddress = new mf_EmployeeAddress()
                {
                    ObjectState = ObjectState.Added
                };
            }
            else
            {
                data.mf_EmployeeAddress.ObjectState = ObjectState.Modified;
            }

            data.mf_EmployeeAddress.address1   = model.address1;
            data.mf_EmployeeAddress.address2   = model.address2;
            data.mf_EmployeeAddress.address3   = model.address3;
            data.mf_EmployeeAddress.countryId  = model.countryId;
            data.mf_EmployeeAddress.city       = model.city;
            data.mf_EmployeeAddress.postalCode = model.postalCode;

            data.mf_EmployeeAddress.updatedBy   = userId;
            data.mf_EmployeeAddress.updatedDate = DateTime.Now;

            data.updatedBy   = userId;
            data.updatedDate = DateTime.Now;

            this._repoEmployee.Update(data);
            this._unitOfWork.Save();
            model.pictureExtension = data.pictureExtension;
        }
示例#6
0
 private void PrepareEmployeeBasicInfoModel(EmployeeBasicInfoModel model)
 {
     model.MaritalStatusList = this._enumReferenceService.GetQuery(ReferenceList.MARITAL_STATUS).ToList();
     model.GenderList        = this._enumReferenceService.GetQuery(ReferenceList.GENDER).ToList();
     model.CountryList       = this._countryService.GetQuery().ToList();
 }