public IHttpActionResult AddPrices(PriceKindDTO priceKindDTO) { var userId = User.Identity.GetUserId(); var currentPersonId = context.Persons.Where(p => p.IdentityUserId == userId).SingleOrDefault().Id; var currentKindId = priceKindDTO.KindId; //Edit if (context.PriceKinds.Where(s => s.PersonId == currentPersonId && s.KindId == currentKindId).Any()) { var currentPriceKind = context.PriceKinds.Where(s => s.PersonId == currentPersonId && s.KindId == currentKindId).Single(); currentPriceKind.Price = priceKindDTO.Price; context.SaveChanges(); }//New else { var pricekind = new PriceKind { Price = priceKindDTO.Price, Person = context.Persons.Where(p => p.IdentityUserId == userId).SingleOrDefault(), KindId = priceKindDTO.KindId }; context.PriceKinds.Add(pricekind); context.SaveChanges(); } return(Ok()); }
public IHttpActionResult Delete(PriceKindDTO priceKindDTO) { var userId = User.Identity.GetUserId(); var currentPersonId = context.Persons.Where(p => p.IdentityUserId == userId).SingleOrDefault().Id; var currentPriceKind = context.PriceKinds.Single(p => p.KindId == priceKindDTO.KindId && p.PersonId == currentPersonId); context.PriceKinds.Remove(currentPriceKind); context.SaveChanges(); return(Ok()); }