public async Task <IActionResult> CreatePlanningApp([FromBody] CreatePlanningAppResource planningResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var planningApp = mapper.Map <CreatePlanningAppResource, PlanningApp>(planningResource); var stateInitialiser = await stateInitialiserRepository.GetStateInitialiser(planningApp.StateInitialiserId, includeDeleted : false); PlanningAppResource result = null; if (stateInitialiser.States.Count > 0) { repository.Add(planningApp, stateInitialiser); await unitOfWork.CompleteAsync(); planningApp = await repository.GetPlanningApp(planningApp.Id, includeRelated : true); //Generate Customer Reference var customer = await customerRepository.GetCustomer(planningApp.CustomerId, includeRelated : false); planningApp.genCustomerReferenceId(customer); await unitOfWork.CompleteAsync(); //Save reference number result = mapper.Map <PlanningApp, PlanningAppResource>(planningApp); result.BusinessDate = CurrentDate.SettingDateFormat(); } return(Ok(result)); }
public async Task <IActionResult> CreateStateInitialiser([FromBody] StateInitialiserSaveResource resource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var stateInitialiser = mapper.Map <StateInitialiserSaveResource, StateInitialiser>(resource); stateInitialiser.LastUpdate = DateTime.Now; stateRepository.Add(stateInitialiser); await unitOfWork.CompleteAsync(); stateInitialiser = await stateRepository.GetStateInitialiser(stateInitialiser.Id); var result = mapper.Map <StateInitialiser, StateInitialiserResource>(stateInitialiser); return(Ok(result)); }