public ActionResult Create(DocumentFieldViewModel model)
        {
            var urlRefer = Request["UrlReferrer"];
            var segments = urlRefer.Split('/');
            var IsSearch = Request["staffListcancel"];

            if (ModelState.IsValid)
            {
                //hàm insert documentfield
                DocumentFieldController.SaveUpload(model.Name, IsSearch, model.CategoryId.HasValue ? model.CategoryId.Value : 0, model.Category);
                //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(model.Id, model.AttributeValueList);

                if (Request["IsPopup"] == "true")
                {
                    ViewBag.closePopup = "close and append to page parent";
                    ViewBag.urlRefer   = urlRefer;
                    //  model.Id = InfoPartyA.Id;
                    return(View(model));
                }

                return(Redirect(urlRefer));
            }
            return(View(model));
        }
Exemple #2
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));
        }