public ActionResult AddUserSuggestion([FromBody] AddSuggestionViewModel model) { try { string userId = User.GetUserIdToken(); if (ModelState.IsValid) { Suggestions newSuggestion = new Suggestions() { UserId = userId, SuggestedModel = model.SuggestedModel, Description = model.Description }; _suggestionRepository.Add(newSuggestion); _suggestionRepository.SaveAll(); return(Ok(new { message = "Suggestion Successfully Added." })); } return(BadRequest("Suggestion Model is not valid.")); } catch { return(BadRequest("An Error Has Occured.")); } }
public IActionResult AddSuggestion(string newCity, string newCountry, string newDescription) { Suggestion newDestination = new Suggestion(newCity, newCountry, newDescription); repo.Add(newDestination); return(Json(repo.AllSuggestions)); }
public IActionResult AddSuggestion([FromBody] Suggestion suggestion, [FromRoute] string userId) { // idee: suggestion invullen vanuit URL, suggestion opsplitsen zodat een kleiner object moet ingevuld worden door user? Logger.Info(this, $"Adding suggestion"); if (suggestion?.Id == null)//suggestion null of Id null: null coalescing operator { return(BadRequest("suggestion id is required")); } var sugg = _suggestionRepository.Get(suggestion.Id); if (sugg != null) { return(BadRequest($"A suggestion with id {suggestion.Id} already exists")); } if (suggestion.UserId != userId) { return(BadRequest("user id doesn't match url")); } if (string.IsNullOrWhiteSpace(suggestion.Name) || string.IsNullOrWhiteSpace(suggestion.Milestone)) { return(BadRequest("suggestion name and/or milestone is required")); } if (suggestion.NumberOfHours <= 0) { return(BadRequest("suggestion type can't be null and/or hours need to be greater than 0")); } _suggestionRepository.Add(suggestion); return(Ok()); }
public ActionResult <Suggestion> PostSuggestion(SuggestionDTO suggestion) { Console.WriteLine("post method called"); Console.WriteLine(suggestion.ToString()); Suggestion suggestionToCreate = new Suggestion() { Name = suggestion.Name, Longtitude = suggestion.Longtitude, Latitude = suggestion.Latitude, Description = suggestion.Description }; _suggestions.Add(suggestionToCreate); _suggestions.SaveChanges(); return(CreatedAtAction(nameof(GetSuggestion), new { id = suggestionToCreate.Id }, suggestionToCreate)); }
public IActionResult Create([FromBody] SuggestionViewModel suggestion) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Suggestion _newSuggestion = Mapper.Map <SuggestionViewModel, Suggestion>(suggestion); _newSuggestion.DateCreated = DateTime.Now; _newSuggestion.DateUpdated = _newSuggestion.DateCreated; _newSuggestion.Status = SuggestionStatus.Nuevo; _suggestionRepository.Add(_newSuggestion); _suggestionRepository.Commit(); suggestion = Mapper.Map <Suggestion, SuggestionViewModel>(_newSuggestion); CreatedAtRouteResult result = CreatedAtRoute("GetSuggestion", new { controller = "Suggestions", id = suggestion.Id }, suggestion); return(result); }
public void AddSuggestion(SuggestionDto suggestionDto) { suggestionDto.CreateTime = DateTime.Now; _suggestionRepository.Add(QsMapper.CreateMap <SuggestionDto, Suggestion>(suggestionDto)); _suggestionRepository.UnitOfWork.Commit(); }