public async Task <PlanningApp> Create(CreatePlanningAppResource planningResource) { var planningApp = Mapper.Map <CreatePlanningAppResource, PlanningApp>(planningResource); //Use when gui setup to create multiple generators //planningApp.ProjectGenerator = ProjectGeneratorRepository.GetProjectGenerator(planningResource.ProjectGeneratorId).Result; //Console.WriteLine("Creating New Planning App, Project Generator -> " + planningApp.ProjectGenerator.Name); //Dummy project multi generator for now planningApp.ProjectGeneratorId = planningResource.ProjectGeneratorId; planningApp.StartDate = SystemDate.Instance.date; //Create Customer planningApp.Customer = CustomerRepository.GetCustomer(planningResource.CustomerId).Result; //Set Status planningApp.CurrentPlanningStatus = statusList.Where(s => s.Name == StatusList.AppInProgress).SingleOrDefault(); //Create States planningApp = await AddSingleGeneratorStates(planningApp); Console.WriteLine("Generated " + planningApp.PlanningAppStates.Count + " Planning States"); //Refactor!!!!!!! if (planningResource.Surveyors != null) { foreach (string surveyorId in planningResource.Surveyors) { PlanningAppSurveyors planningAppSurveyors = new PlanningAppSurveyors(); planningAppSurveyors.PlanningApp = planningApp; planningAppSurveyors.AppUser = await UserManager.FindByIdAsync(surveyorId); planningApp.Surveyors.Add(planningAppSurveyors); } } if (planningResource.Drawers != null) { foreach (string surveyorId in planningResource.Drawers) { PlanningAppDrawers planningAppDrawers = new PlanningAppDrawers(); planningAppDrawers.PlanningApp = planningApp; planningAppDrawers.AppUser = await UserManager.FindByIdAsync(surveyorId); planningApp.Drawers.Add(planningAppDrawers); } } if (planningResource.Admins != null) { foreach (string adminId in planningResource.Admins) { PlanningAppAdmins planningAppAdmins = new PlanningAppAdmins(); planningAppAdmins.PlanningApp = planningApp; planningAppAdmins.AppUser = await UserManager.FindByIdAsync(adminId); planningApp.Admins.Add(planningAppAdmins); } } //Create Fees foreach (var fee in FeeRepository.GetFeesDefault()) { PlanningAppFees planningAppFees = new PlanningAppFees { Amount = fee.DefaultAmount, Fee = fee }; planningApp.Fees.Add(planningAppFees); } //Persist planning app PlanningAppRepository.Add(planningApp); await UnitOfWork.CompleteAsync(); //Create Reference using planning id planningApp.PlanningReferenceId = genCustomerReferenceId(planningApp); PlanningAppRepository.UpdatePlanningApp(planningApp); await UnitOfWork.CompleteAsync(); //Retrieve planning app from database and return results to controller return(await PlanningAppRepository.GetPlanningApp(planningApp.Id, includeRelated : false)); }
public void SavePlanningApp(PlanningApp planningApp) { PlanningAppRepository.Add(planningApp); }