public ActionResult Post(Event Model) { try { if (!ModelState.IsValid) { return(BadRequest("Data can not be saved")); } if (EventRepository.AlreadyExists(Model.Title, Model.UserId, Model.Date)) { return(BadRequest("Record already exists")); } string Message; if (!EventRepository.ValidateInput(Model, out Message)) { return(BadRequest(Message)); } User User = UserRepository.Get(Model.UserId); if (User == null) { return(BadRequest("Invalid CreatedBy. User id does not exists.")); } EventRepository.Add(Model); EventRepository.Save(); return(Ok("Record Saved")); } catch (Exception) { return(BadRequest("Record can not be saved")); } }