public async Task <IActionResult> Create(PlanDto create) { if (_planService.GetById(create.ID) != null) { return(BadRequest("Plan ID already exists!")); } create.CreatedDate = DateTime.Now; return(Ok(await _planService.Add(create))); }
public IActionResult Add(Plan plan) { var result = _planService.Add(plan); if (result.Success) { return(Ok(result.Message)); } return(BadRequest(result.Message)); }
public ActionResult Add(PlanAddModel model) { if (!ModelState.IsValid) { return(View(model)); } _planService.Add(model); return(RedirectToAction("index") .AndAlert(AlertType.Success, "Success.", "Plan added successfully.")); }
public async Task <IActionResult> Create(PlanDto create) { if (_planService.GetById(create.ID) != null) { return(BadRequest("Plan ID already exists!")); } create.CreatedDate = DateTime.Now; if (await _planService.Add(create)) { return(NoContent()); } throw new Exception("Creating the model no failed on save"); }
public async Task <IActionResult> Create(PlanDto create) { if (_planService.GetById(create.ID) != null) { return(BadRequest("Plan ID already exists!")); } create.CreatedDate = DateTime.Now; var model = await _planService.Add(create); if (model) { await _hubContext.Clients.All.SendAsync("ReceiveCreatePlan"); } return(Ok(model)); }
// POST: api/plan public HttpResponseMessage Post([FromBody] PlanDTO value) { try { var success = planService.Add(value); if (success) { var okMessage = $"Succesfully created plan: {value.Name}"; return(Request.CreateResponse(HttpStatusCode.OK, okMessage)); } } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } var message = "Incorrect request syntax."; return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, message)); }
public HttpResponseMessage Post([FromBody] PlanDTO value) { try { var success = planService.Add(value); if (success) { var log = $"Succesfully created plan {value.Name} with id = {value.Id} by user with id = {value.CreatorId}"; tracer.Info(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, log); var okMessage = $"Succesfully created plan: {value.Name}"; return(Request.CreateResponse(HttpStatusCode.OK, okMessage)); } } catch (EntityException e) { tracer.Error(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, e); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } tracer.Warn(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, "Error occured on creating plan"); const string message = "Incorrect request syntax."; return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, message)); }