public async Task <ActionResult> Create(EventViewModel model, HttpPostedFileBase image) { if (!ModelState.IsValid) { return(Json(new { success = false, errors = ModelState.Keys.SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray() })); } try { string url; url = GetImageUrl(image, out string path); var create = new Event { CreatedBy = User.Identity.GetUserId <int>(), Title = model.Title, LayoutId = model.LayoutId, ImageURL = url, Date = model.Date.Date + model.Time.TimeOfDay, Description = model.Description }; await _eventService.CreateAsync(create); if (!string.IsNullOrEmpty(path)) { image.SaveAs(path); } } catch (FaultException <ServiceValidationFaultDetails> exception) { string error = exception.Message; if (exception.Message.Equals("Invalid date", StringComparison.OrdinalIgnoreCase)) { error = ProjectResources.ResourceErrors.EventInvalidDateError; } if (exception.Message.Equals("Attempt of creating event with a date in the past", StringComparison.OrdinalIgnoreCase)) { error = ProjectResources.ResourceErrors.PastDateError; } return(Json(new { success = false, errors = new string[] { error } })); } catch (FaultException exception) { return(Json(new { success = false, error = exception.Message })); } return(Json(new { success = true })); }