Пример #1
0
        public ActionResult Create(LabourContractViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user           = userRepository.GetUserById(WebSecurity.CurrentUserId);
                var LabourContract = new LabourContract();
                AutoMapper.Mapper.Map(model, LabourContract);
                LabourContract.IsDeleted      = false;
                LabourContract.CreatedUserId  = WebSecurity.CurrentUserId;
                LabourContract.ModifiedUserId = WebSecurity.CurrentUserId;
                LabourContract.AssignedUserId = WebSecurity.CurrentUserId;
                LabourContract.CreatedDate    = DateTime.Now;
                LabourContract.ModifiedDate   = DateTime.Now;
                LabourContract.Status         = "Còn hiệu lực";

                var q = LabourContractTypeRepository.GetLabourContractTypeById(model.Type.Value);
                if (Convert.ToInt32(model.Type) > 0)
                {
                    LabourContract.ExpiryDate = model.EffectiveDate.Value.AddMonths(Convert.ToInt32(q.QuantityMonth));
                }
                //lấy thông tin nhân viên lúc ký hợp đồng lưu lại.
                var staff = staffRepository.GetvwStaffsById(model.StaffId.Value);
                //LabourContract.DepartmentStaffId = staff.BranchDepartmentId;
                LabourContract.PositionStaff = staff.PositionId.Value.ToString();
                //lấy thông tin người đại diện công ty ký.
                var approved = staffRepository.GetvwStaffsById(model.ApprovedUserId.Value);
                //LabourContract.DepartmentApprovedId = approved.BranchDepartmentId;
                //LabourContract.PositionApproved = approved.Position;
                LabourContractRepository.InsertLabourContract(LabourContract);
                //tạo mã hợp đồng lao động
                var prefix = Erp.BackOffice.Helpers.Common.GetSetting("prefixOrderNo_LabourContract");
                LabourContract.Code = Erp.BackOffice.Helpers.Common.GetCode(prefix, LabourContract.Id);
                LabourContractRepository.UpdateLabourContract(LabourContract);
                //lưu các trường thuộc tính động.
                //tạo hoặc cập nhật đặc tính động cho sản phẩm nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị
                Sale.Controllers.ObjectAttributeController.CreateOrUpdateForObject(LabourContract.Id, model.AttributeValueList);
                //lưu file
                DocumentFieldController.SaveUpload(LabourContract.Code, "", LabourContract.Id, "LabourContract");
                //tạo quá trình lương cho nhân viên
                Staff.Controllers.ProcessPayController.CreateProcessPay(model.StaffId, model.WageAgreement, model.EffectiveDate);
                //cập nhật ngày vào làm, ngày nghỉ vào thông tin nhân viên
                Staff.Controllers.StaffsController.UpdateStaff(model.StaffId, model.EffectiveDate, LabourContract.ExpiryDate);
                //
                var labourcontract = LabourContractRepository.GetvwLabourContractById(LabourContract.Id);
                CreateLabourContract(labourcontract);
                TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess + " " + LabourContract.Code;

                return(RedirectToAction("Index"));
            }
            TempData[Globals.FailedMessageKey] = App_GlobalResources.Error.InsertUnsucess;
            return(View(model));
        }
        public ActionResult Edit(int?Id)
        {
            var LabourContractType = LabourContractTypeRepository.GetLabourContractTypeById(Id.Value);

            if (LabourContractType != null && LabourContractType.IsDeleted != true)
            {
                var model = new LabourContractTypeViewModel();
                AutoMapper.Mapper.Map(LabourContractType, model);

                //if (model.CreatedUserId != Erp.BackOffice.Helpers.Common.CurrentUser.Id && Erp.BackOffice.Helpers.Common.CurrentUser.UserTypeId != 1)
                //{
                //    TempData["FailedMessage"] = "NotOwner";
                //    return RedirectToAction("Index");
                //}

                return(View(model));
            }
            if (Request.UrlReferrer != null)
            {
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }
            return(RedirectToAction("Index"));
        }