public ActionResult Add(Choice choice) { try { var model = _repository.Add(choice); return new HttpStatusCodeResult(HttpStatusCode.Created, "New choice was created with id: " + model.ChoiceId); } catch (Exception ex) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } }
public Choice Add(Choice choice) { try { var newChoice = new Choice() { ChoiceId = ObjectId.GenerateNewId().ToString(), CategoryId = choice.CategoryId, Details = choice.Details, Name = choice.Name }; var returned = _choices.InsertOneAsync(newChoice.ToBsonDocument()); returned.Wait(); _log.Debug("New choice added with id: " + newChoice.ChoiceId); return newChoice; } catch (Exception ex) { _log.Exception(ex.Message + ex.InnerException); throw; } }