public async Task <ActionResult <Response <Thing> > > PostThing(ThingDTO thingDTO) { Thing thing = new Thing { Owner = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value), Users = new List <Policy>(), Type = thingDTO.Type, Features = thingDTO.Features }; thingDTO.Users.ForEach(user => { thing.Users.Add(new Policy { User = user }); }); _context.Thing.Add(thing); await _context.SaveChangesAsync(); UpdateThingsAndPolicies(_context); return(CreatedAtAction("GetThing", new { Id = thing.ThingId }, thing)); }
public async Task <IActionResult> PutThing(Guid Id, ThingDTO thingDTO) { var thing = await _context.Thing.Include(thing => thing.Users).Where(thing => thing.ThingId.Equals(Id)).FirstOrDefaultAsync(); if (thing == null) { return(NotFound()); } thing.MapFromDTO(thingDTO); _context.Entry(thing).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } UpdateThingsAndPolicies(_context); return(NoContent()); }
public static Thing convertToThing(ThingDTO tDTO) { Thing thing = new Thing(); thing.ThingID = tDTO.id; thing.Num_Uscite = tDTO.numUscite; thing.Prezzo = tDTO.prezzo; if (tDTO.customer != null) { thing.Customer = CustomerConverter.convertToCustomer(tDTO.customer); } else { thing.Customer = null; } thing.Building = BuildingConverter.convertToBuilding(tDTO.building); return(thing); }
public static ThingDTO convertToDto(Thing t) { ThingDTO thingDTO = new ThingDTO(); thingDTO.id = t.ThingID; thingDTO.numUscite = t.Num_Uscite; thingDTO.prezzo = t.Prezzo; if (t.Customer != null) { thingDTO.customer = CustomerConverter.convertToDto(t.Customer); } else { thingDTO.customer = null; } thingDTO.building = BuildingConverter.convertToDto(t.Building); return(thingDTO); }