Example #1
0
        public ResponseObject <bool> UpdateContract(ContractAPIViewModel model)
        {
            var contractService = this.Service <IContractService>();

            var result = contractService.UpdateContract(model);

            return(result);
        }
        public ResponseObject <ContractAPIViewModel> ViewDetail(int contract_id)
        {
            try
            {
                var contractRepo        = DependencyUtils.Resolve <IContractRepository>();
                var contractServiceRepo = DependencyUtils.Resolve <IContractServiceITSupportRepository>();
                var contract            = contractRepo.GetActive().SingleOrDefault(a => a.ContractId == contract_id);
                var contractService     = contractServiceRepo.GetActive().Where(a => a.ContractId == contract_id).ToList();
                if (contract != null)
                {
                    List <int>    listId   = new List <int>();
                    List <string> listName = new List <string>();

                    foreach (var item in contractService)
                    {
                        listId.Add(item.ServiceITSupportId);
                    }
                    foreach (var item in contractService)
                    {
                        listName.Add(item.ServiceITSupport.ServiceName);
                    }
                    var contractAPIViewModel = new ContractAPIViewModel
                    {
                        ContractId       = contract.ContractId,
                        CompanyId        = contract.CompanyId,
                        CompanyName      = contract.Company.CompanyName,
                        ContractName     = contract.ContractName,
                        ServiceIdList    = listId,
                        ServiceName      = listName,
                        StartDate        = contract.StartDate.Value.ToString("dd/MM/yyyy"),
                        EndDate          = contract.EndDate.Value.ToString("dd/MM/yyyy"),
                        ContractStatus   = contract.EndDate != null && contract.EndDate.Value.Date < DateTime.Now.Date ? "Hợp đồng hết hạn" : string.Empty,
                        UpdateDate       = contract.UpdateDate.Value.ToString("dd/MM/yyyy"),
                        ContractPrice    = contract.ContractPrice,
                        EndDateCountDown = contract.EndDate != null ? ((contract.EndDate.Value.Date - DateTime.Now.Date).Days > 0 ? (contract.EndDate.Value.Date - DateTime.Now.Date).Days.ToString() : "Hết hạn") : string.Empty
                    };
                    return(new ResponseObject <ContractAPIViewModel> {
                        IsError = false, ObjReturn = contractAPIViewModel, SuccessMessage = "Lấy chi tiết thành công"
                    });
                }
                return(new ResponseObject <ContractAPIViewModel> {
                    IsError = true, WarningMessage = "Không tồn tại hợp đồng này"
                });
            }
            catch (Exception e)
            {
                return(new ResponseObject <ContractAPIViewModel> {
                    IsError = true, WarningMessage = "Không tồn tại hợp đồng này", ObjReturn = null, ErrorMessage = e.ToString()
                });
            }
        }
        public ResponseObject <bool> CreateContract(ContractAPIViewModel model)
        {
            try
            {
                var contractRepo   = DependencyUtils.Resolve <IContractRepository>();
                var createContract = new Contract();

                createContract.CompanyId     = model.CompanyId;
                createContract.ContractName  = model.ContractName;
                createContract.StartDate     = model.StartDate.ToDateTime();
                createContract.EndDate       = model.EndDate.ToDateTime();
                createContract.IsDelete      = false;
                createContract.CreateDate    = DateTime.UtcNow.AddHours(7);
                createContract.UpdateDate    = DateTime.UtcNow.AddHours(7);
                createContract.ContractPrice = model.ContractPrice;

                contractRepo.Add(createContract);
                contractRepo.Save();

                var contractServiceRepo = DependencyUtils.Resolve <IContractServiceITSupportRepository>();

                foreach (var item in model.ServiceIdList)
                {
                    var contractService = new ContractServiceITSupport()
                    {
                        ContractId         = createContract.ContractId,
                        ServiceITSupportId = item,
                        IsDelete           = false,
                        StartDate          = model.StartDate.ToDateTime(),
                        EndDate            = model.EndDate.ToDateTime(),
                        CreateDate         = DateTime.UtcNow.AddHours(7),
                        UpdateDate         = DateTime.UtcNow.AddHours(7)
                    };

                    contractServiceRepo.Add(contractService);
                }
                contractServiceRepo.Save();

                return(new ResponseObject <bool> {
                    IsError = false, SuccessMessage = "Thêm hợp đồng thành công", ObjReturn = true
                });
            }
            catch (Exception ex)
            {
                return(new ResponseObject <bool> {
                    IsError = true, WarningMessage = "Thêm hợp đồng thất bại", ErrorMessage = ex.ToString(), ObjReturn = false
                });
            }
        }
        public ActionResult UpdateContract(ContractAPIViewModel model)
        {
            var result = _contractDomain.UpdateContract(model);

            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
        public ResponseObject <bool> UpdateContract(ContractAPIViewModel model)
        {
            try
            {
                var contractRepo        = DependencyUtils.Resolve <IContractRepository>();
                var contractServiceRepo = DependencyUtils.Resolve <IContractServiceITSupportRepository>();
                var updateContract      = contractRepo.GetActive().SingleOrDefault(a => a.ContractId == model.ContractId);
                var contractService     = contractServiceRepo.GetActive().Where(a => a.ContractId == model.ContractId).ToList();

                foreach (var itemFE in model.ServiceIdList)
                {
                    if (!contractService.Select(x => x.ServiceITSupportId).ToList().Contains(itemFE))
                    {
                        var contractServiceNew = new ContractServiceITSupport()
                        {
                            ContractId         = model.ContractId,
                            ServiceITSupportId = itemFE,
                            IsDelete           = false,
                            StartDate          = model.StartDate.ToDateTime(),
                            EndDate            = model.EndDate.ToDateTime(),
                            CreateDate         = DateTime.UtcNow.AddHours(7),
                            UpdateDate         = DateTime.UtcNow.AddHours(7),
                        };
                        contractServiceRepo.Add(contractServiceNew);
                    }
                }

                foreach (var itemDB in contractService)
                {
                    if (!model.ServiceIdList.Contains(itemDB.ServiceITSupportId))
                    {
                        itemDB.UpdateDate = DateTime.UtcNow.AddHours(7);
                        contractServiceRepo.Deactivate(itemDB);
                    }
                }
                contractServiceRepo.Save();

                if (updateContract != null)
                {
                    updateContract.ContractName  = model.ContractName;
                    updateContract.StartDate     = model.StartDate.ToDateTime();
                    updateContract.EndDate       = model.EndDate.ToDateTime();
                    updateContract.UpdateDate    = DateTime.UtcNow.AddHours(7);
                    updateContract.ContractPrice = model.ContractPrice;

                    contractRepo.Edit(updateContract);
                    contractRepo.Save();
                    return(new ResponseObject <bool> {
                        IsError = false, SuccessMessage = "Chỉnh sửa hợp đồng thành công", ObjReturn = true
                    });
                }

                return(new ResponseObject <bool> {
                    IsError = true, WarningMessage = "Chỉnh sửa hợp đồng thất bại", ObjReturn = false
                });
            }
            catch (Exception e)
            {
                return(new ResponseObject <bool> {
                    IsError = true, WarningMessage = "Chỉnh sửa hợp đồng thất bại", ObjReturn = false, ErrorMessage = e.ToString()
                });
            }
        }