public IActionResult Create([FromBody] Slot slot) { //Check if staff was submitted if (slot == null) { return(NotFound(new { status = "fail", message = "Slot information must be supplied" })); } //Check if the slot already exists var slotExists = repo.Find(slot.RoomID, slot.StartTime); if (slotExists != null) { return(NotFound(new { status = "fail", message = "Matching slot already exists" })); } //Check is a valid slot model if (ModelState.IsValid) { //Create the slot var newSlot = repo.Create(slot); //Check the slot was created if (newSlot != null) { return(Ok(new { status = "success", message = "Slot has been created", data = new { slot = newSlot } })); } } return(NotFound(new { status = "fail", message = "Cannot save slot", data = ModelState.Values.Select(v => v.Errors) })); }
public IActionResult Create(Slot slot) { //Check model is valid if (ModelState.IsValid) { //Validate slot via business rules var newSlot = ValidateCreateSlot(slot.RoomID, slot.StartTime, slot.StaffID); if (newSlot != null) { _repo.Create(slot); return View(new SlotCreateViewModel { Slot = new Slot(), Result = "Slot created successfuly", }); } return View(new SlotCreateViewModel { Slot = slot, Result = "Failed to create slot: Breaks business rules", }); } return View(new SlotCreateViewModel { Slot = slot, Result = "Failed to create slot: Model invalid", }); }
public async Task <Slot> Create(Slot obj) { Slot result = new Slot(); if (validation.CheckValidation(obj)) { result = await repository.Create(obj); } return(result); }