public async Task Add(int productId, int addressId, int types) { this.DbSet.Add(new ProductFBO { FboTypes = (FboTypes)types, AddressId = addressId, ProductId = productId }); await ctx.SaveChangesAsync(); }
/// <summary> /// Add can be done in various situations Tags optional, but 0 must be atleast passed. /// </summary> /// <param name="hostId"></param> /// <param name="note"></param> /// <returns></returns> public async Task <SimsNote> Add(int hostId, string note, int tags) { var newComment = new NoteDb { Note = note, HostId = hostId, TagFlags = tags }; this.NoteSet.Add(newComment); var incident = this.NoteSet.SingleOrDefault(p => p.Id == hostId); await ctx.SaveChangesAsync(); return(mapper.Map <NoteDb, SimsNote>(newComment)); }
public async Task <SimsAttachmentFileInfo> Add(int hostId, string docUrl, int tags = 0) { var newItem = this.DbSet.Add(new AttachmentDb { DocUrl = docUrl, HostId = hostId, TagFlags = (DocumentTagTypes)tags }); await ctx.SaveChangesAsync(); return(mapper.Map <AttachmentDb, SimsAttachmentFileInfo>(newItem.Entity)); }
public async Task <SimsProduct> Add(int HostId, SimsProduct newProduct) { if (HostId == 0) { throw new ArgumentOutOfRangeException("No host selected."); } var dbItem = mapper.Map <SimsProduct, T>(newProduct); dbItem.HostId = HostId; var dbCreated = DbSet.Add(dbItem); await ctx.SaveChangesAsync(); return(mapper.Map <T, SimsProduct>(dbCreated.Entity)); }
/// <summary> /// Update only a classification in an incident /// </summary> /// <param name="id"></param> /// <param name="ClassificationId"></param> /// <returns> /// The updated incident /// </returns> /// <exception cref="NullReferenceException" /> public async Task <BaseIncident> UpdateClassification(int id, int ClassificationId) { if (await this.IsClosed(id)) { throw new ArgumentOutOfRangeException("Cannot update a closed incident."); } var dbItem = await ctx.Incidents.FindAsync(id); dbItem.ClassificationId = ClassificationId; await ctx.SaveChangesAsync(); return(mapper.Map <IncidentDb, BaseIncident>(dbItem)); }
/// <summary> /// TO DO !!!! /// </summary> /// <param name="address"></param> /// <returns></returns> public async Task <SimsAddress> Update(SimsAddress address) { var dbItem = await ctx.Addresses.Include(i => i.Contacts).SingleAsync(s => s.Id == address.Id); // Updates the address details this.mapper.Map(address, dbItem); //address.ToDb(dbItem); ctx.Addresses.Update(dbItem); // Main Contact. We don't have the key for contacins. // Currently (25/08/2020) you may only add one contact. // so hear we either update an existing contact (is always main), or add a new one. if (address.Contacts.Count() > 0) { var firstContact = address.Contacts.First(); if (dbItem.Contacts.Count() > 0) { var dbContact = dbItem.Contacts.First(); this.mapper.Map(firstContact, dbContact); //firstContact.ToDb(dbContact); } else { var newDbContact = mapper.Map <SimsAddressContact, AddressContactDb>(firstContact); dbItem.Contacts.Add(newDbContact); } await ctx.SaveChangesAsync(); } return(mapper.Map <AddressDb, SimsAddress>(dbItem)); }
public async Task AddBatch(IEnumerable <SimsSignal> signals) { foreach (var signal in signals) { var dbItem = this.ToDb(signal); this.ctx.Signals.Add(dbItem); } await ctx.SaveChangesAsync(); }
public async Task <SimsStakeholder> Add(int hostId, SimsStakeholder stakeholder) { if (hostId == 0) { throw new ArgumentOutOfRangeException("Host Id missing."); } if (stakeholder.Id > 0) { throw new ArgumentException("Stakeholder already exists."); } // Cannot add an FSA member with an address, this is an application error. stakeholder.HostId = hostId; var toDb = mapper.Map <SimsStakeholder, T>(stakeholder); var dbItem = this.DbSet.Add(toDb); await ctx.SaveChangesAsync(); return(this.mapper.Map <T, SimsStakeholder>(dbItem.Entity)); }
public Task LogEntry(string IncidentOrSignal, string PageRef, int ItemId) { ctx.UserAccessLog.Add(new UserAccessAuditDb { UserId = ctx.Editor, Scope = IncidentOrSignal, Page = PageRef, ScopeId = ItemId }); return(ctx.SaveChangesAsync()); }
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 <SimsLinkedRecord> Remove(int from, int to) { // LOcal functions fancy. // Cos the logic is annoying and I'm not confident in it yet. // Why should we update the host object? async Task <SimsLinkedRecord> DeleteLink(LinkDb link) { this.LinkSet.Remove(link); //var fromIncident = this.LinkSet.Find(link.FromId); //var toincident = this.LinkSet.Find(link.ToId); await ctx.SaveChangesAsync(); return(new SimsLinkedRecord { From = from, To = to }); } var linkData = this.LinkSet.Find(from, to); if (linkData == null) { // try the other way instead to-from linkData = this.LinkSet.Find(to, from); } if (linkData != null) { return(await DeleteLink(linkData)); } else { return new SimsLinkedRecord { From = 0, To = 0 } }; }