public JsonResult UpdateProviderContract([DataSourceRequest] DataSourceRequest request, ProviderContractViewModel contract) { foreach (var propertyName in ModelState.Select(modelError => modelError.Key)) { if (propertyName.Contains("Provider")) { ModelState[propertyName].Errors.Clear(); } } if (contract == null || !ModelState.IsValid) { return Json(new[] { contract }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); } var updatedContract = this.contracts.UpdateProviderContract(contract); var loggedUserId = this.User.Identity.GetUserId(); Base.CreateActivity(ActivityType.Edit, updatedContract.Id.ToString(), ActivityTargetType.Contract, loggedUserId); return Json((new[] { updatedContract }.ToDataSourceResult(request, ModelState)), JsonRequestBehavior.AllowGet); }
public JsonResult DestroyProviderContract([DataSourceRequest] DataSourceRequest request, ProviderContractViewModel contract) { var deletedContract = this.contracts.DestroyProviderContract(contract); var loggedUserId = this.User.Identity.GetUserId(); Base.CreateActivity(ActivityType.Delete, contract.Id.ToString(), ActivityTargetType.Contract, loggedUserId); return Json(new[] { deletedContract }, JsonRequestBehavior.AllowGet); }
public JsonResult CreateProviderContract([DataSourceRequest] DataSourceRequest request, ProviderContractViewModel contract, int currentProviderId) { if (contract.StartDate != null) { contract.StartDate = DateTime.Parse(contract.StartDate.ToString()); } if (contract.EndDate != null) { contract.EndDate = DateTime.Parse(contract.EndDate.ToString()); } if (contract.BillingEndDate != null) { contract.BillingEndDate = DateTime.Parse(contract.BillingEndDate.ToString()); } if (contract.BillingStartDate != null) { contract.BillingStartDate = DateTime.Parse(contract.BillingStartDate.ToString()); } if (contract == null) { return Json(new[] { contract }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); } var newContract = this.contracts.CreateProviderContract(contract, currentProviderId); var loggedUserId = this.User.Identity.GetUserId(); Base.CreateActivity(ActivityType.Create, newContract.Id.ToString(), ActivityTargetType.Contract, loggedUserId); contract.Id = newContract.Id; return Json(new[] { newContract }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); }
public ProviderContractViewModel UpdateProviderContract(ProviderContractViewModel contract) { var contractFromDb = this.Data.ProviderContracts .All() .FirstOrDefault(c => c.Id == contract.Id); contractFromDb.StartDate = contract.StartDate; contractFromDb.TypeOfContract = contract.TypeOfContract; contractFromDb.EndDate = contract.EndDate; contractFromDb.NoticePeriod = contract.NoticePeriod; contractFromDb.BillingStartDate = contract.BillingStartDate; contractFromDb.BillingEndDate = contract.BillingEndDate; contractFromDb.NumberOfDaysForPaymentDueDate = contract.NumberOfDaysForPaymentDueDate; contractFromDb.AcceptingReports = contract.AcceptingReports; contractFromDb.GoverningLaw = contract.GoverningLaw; contractFromDb.CreatedOn = DateTime.Now; contractFromDb.Comments = contract.Comments; contractFromDb.IsVisible = contract.IsVisible; contractFromDb.AnnualIndexation = contract.AnnualIndexation; this.Data.SaveChanges(); return contract; }
public ProviderContractViewModel DestroyProviderContract(ProviderContractViewModel contract) { this.Data.ProviderContracts.Delete(contract.Id); this.Data.SaveChanges(); return contract; }
public ProviderContractViewModel CreateProviderContract(ProviderContractViewModel contract, int currentProviderId) { var providerType = int.Parse(this.Data.Providers .GetById(currentProviderId) .TypeOfCompany); var type = this.Data.TypeOfCompanies .GetById(providerType) .Type; var newContract = new ProviderContract { StartDate = contract.StartDate, TypeOfContract = type, EndDate = contract.EndDate, NoticePeriod = contract.NoticePeriod, BillingStartDate = contract.BillingStartDate, BillingEndDate = contract.BillingEndDate, NumberOfDaysForPaymentDueDate = contract.NumberOfDaysForPaymentDueDate, AcceptingReports = contract.AcceptingReports, GoverningLaw = contract.GoverningLaw, ProviderId = currentProviderId, CreatedOn = DateTime.Now, Comments = contract.Comments, AnnualIndexation = contract.AnnualIndexation, IsVisible = contract.IsVisible }; this.Data.ProviderContracts.Add(newContract); this.Data.SaveChanges(); contract.Id = newContract.Id; return contract; }