public async Task <ActionResult <Offer> > Edit(OfferRequest request) { Guid offerId = request.Id.Value; Offer offer = ctx.Offers.Find(offerId); offer.Name = request.Name; offer.Fields = request.Fields.Select(v => new Offer_Field { OfferId = offerId, FieldId = v }).ToList(); offer.Skills = request.Skills.Select(v => new Offer_Skill { OfferId = offerId, SkillId = v }).ToList(); //Kann null sein!! offer.Gender = request.Gender; offer.DateOfBirth = request.Age != null?DateTime.UtcNow.AddYears(-request.Age.Value) : null as DateTime?; offer.Phone = request.Phone; offer.Email = request.Email; offer.LastWorked = request.LastWorked; offer.AvailableFrom = request.AvailableFrom; offer.CoronaPassed = request.CoronaPassed; offer.Address = request.Address; offer.Radius = request.Radius; offer.Comment = request.Comment; offer.Distance = new Random().Next(1, 100); await ctx.SaveChangesAsync(); return(Ok(offer)); }
public async Task <ActionResult <Offer> > Create(OfferRequest request) { Guid offerId = Guid.NewGuid(); Offer offer = new Offer() { Id = offerId, Name = request.Name, Fields = request.Fields.Select(v => new Offer_Field { OfferId = offerId, FieldId = v }).ToList(), Skills = request.Skills.Select(v => new Offer_Skill { OfferId = offerId, SkillId = v }).ToList(), //Kann null sein!! Gender = request.Gender, DateOfBirth = request.Age != null?DateTime.UtcNow.AddYears(-request.Age.Value) : null as DateTime?, Phone = request.Phone, Email = request.Email, LastWorked = request.LastWorked, AvailableFrom = request.AvailableFrom, CoronaPassed = request.CoronaPassed, Address = request.Address, Radius = request.Radius, Comment = request.Comment, Distance = new Random().Next(1, 100) }; ctx.Offers.Add(offer); await ctx.SaveChangesAsync(); return(Created("odata/Contacts", offer)); }