public async Task <SimsOnlineForm> Update(SimsOnlineForm onlineForm) { if (await dbHost.OnlineForms.IsClosed(onlineForm.CommonId) == true) { throw new SimsOnlineFormClosedException("Form is closed"); } return(await dbHost.OnlineForms.Update(onlineForm)); }
public async Task <SimsOnlineForm> Add(SimsOnlineForm onlineForm) { if (onlineForm.CommonId != 0) { throw new SimsItemExists("Online form exists"); } return(await dbHost.OnlineForms.Add(onlineForm)); }
public async Task <SimsOnlineForm> Add(SimsOnlineForm onlineForm) { var newEntity = mapper.Map <OnlineFormDb>(onlineForm); var ent = await ctx.AddAsync(newEntity); await ctx.SaveChangesAsync(); return(mapper.Map <SimsOnlineForm>(ent.Entity)); }
public async Task <IActionResult> UpdateOnlineForm([FromBody, SwaggerParameter("Updated Signal", Required = true)] SimsOnlineForm onlineForm) { try { var result = await simsApp.OnlineForms.Update(onlineForm); return(new OkObjectResult(result)); } catch (SIMSException ex) { return(new BadRequestObjectResult(ex.Message)); } }
public async Task <SimsOnlineForm> Update(SimsOnlineForm onlineForm) { var dbEnt = this.ctx.OnlineForms.Find(onlineForm.CommonId); if (dbEnt == null) { throw new NullReferenceException("Cannot find Online form"); } if (dbEnt.IsClosed) { throw new AccessViolationException("Online form closed."); } if (!dbEnt.IsClosed && onlineForm.IsClosed == true) { throw new DataMisalignedException("Cannot close Online form. Incorrect method."); } mapper.Map(onlineForm, dbEnt); ctx.Update(dbEnt); await ctx.SaveChangesAsync(); return(this.mapper.Map <SimsOnlineForm>(dbEnt)); }
private async Task CreateNewOnlineForm(string refId, ExternalOnlineForm externalFrom, ExternalStakeholder notifier, ExternalAddress notifierAddress, List <ExternalProduct> allProducts, List <ExternalCompany> contacts) { logger.LogDebug("Creating new online form."); var countries = this.host.Lookups.Countries.ToList(); var newForm = ToOnlineForm(externalFrom, refId); var stakeHolder = ToOnlineStakeHolder(notifier); var stakeholderAddressNote = NotifierAddress(notifierAddress, countries); var products = allProducts.Select(p => ToOnlineProduct(p)); SimsOnlineForm addedForm = null; try { logger.LogDebug("Adding onlineform - base"); addedForm = await this.host.OnlineForms.Add(newForm); } catch (Exception ex) { logger.LogCritical("Failed to add basic form", ex); throw ex; } try { logger.LogDebug("Adding onlineform - stakeholders"); // var stakeholders = await this.host.OnlineForms.Stakeholders.Add(addedForm.CommonId, stakeHolder); await this.host.OnlineForms.Notes.Add(addedForm.CommonId, $"Stakeholder Address\n{stakeHolder.Name}\n{stakeHolder.Role}\n{stakeHolder.Phone}\n{stakeholderAddressNote.Note}", 5); } catch (Exception ex) { logger.LogCritical("Failed to add stakeholders", ex); throw ex; } try { logger.LogDebug($"Adding onlineform - products {products.Count()}"); await this.host.OnlineForms.Products.BulkAdd(addedForm.CommonId, products); } catch (Exception ex) { logger.LogCritical("Failed to add products", ex); throw ex; } // unfurl the FBO Types var contactNotes = new List <(string text, int tags)>(); foreach (var contact in contacts) { var contactAddressNote = NotifierAddress(contact.Addresses, countries); var FboTypes = String.Join("\n", host.OnlineForms.Products.Fbos.GetNamesFromId(contact.FbosTypes.ToList())); var updatedNoteText = $"Product Address\nProduct : {contact.ProductName}\nFBOTypes : {FboTypes}\nAddress : {contactAddressNote.Note}"; contactNotes.Add((updatedNoteText, 0)); } try { logger.LogDebug($"Adding onlineform - notes"); await this.host.OnlineForms.Notes.BulkAdd(addedForm.CommonId, contactNotes); } catch (Exception ex) { logger.LogCritical("Failed to add notes", ex); throw ex; } }