public HttpResponseMessage DeleteWidget([FromBody()] WidgetRemoveModel widget) { var result = false; if (ModelState.IsValid) { result = _WidgetsRepository.DeleteWidget(widget); } var model = JsonConvert.SerializeObject(result); var response = this.Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(model, Encoding.UTF8, "application/json"); return(response); }
public bool DeleteWidget(WidgetRemoveModel widgetModel) { var result = false; var FromDb = _db.UserWidgets.Where(x => x.UserId == widgetModel.UserId && x.Id == widgetModel.Id).FirstOrDefault(); if (FromDb != null) { _db.UserWidgets.Remove(FromDb); } try { if (_db.SaveChanges() > 0) { result = true; } } catch (DbEntityValidationException ex) { } return(result); }