public async Task <IActionResult> Create(GuestCreateViewModel model) { if (ModelState.IsValid) { if (model.FromDate >= DateTime.UtcNow.Date && model.ToDate > DateTime.UtcNow.Date) { var guest = new Guest { Id = model.Id, MobileNo = model.MobileNo, Email = model.Email, Address = model.Address, FirstName = model.FirstName, LastName = model.LastName, RoomType = model.RoomType, FromDate = model.FromDate, ToDate = model.ToDate, TotalCharges = _guestService.GetTotalCharges(model.FromDate, model.ToDate, _guestService.PerDayCharges(model.RoomType)) }; await _guestService.CreateAsync(guest); return(RedirectToAction(nameof(Index))); } } return(View()); }
public async Task <IActionResult> Create([FromBody] Guest model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _GuestService.CreateAsync(model); if (!result.Succeeded) { return(BadRequest(result.Errors)); } return(Ok(result)); }
public async Task <IActionResult> Create([FromBody] GuestDto model) { if (!ModelState.IsValid) { _logger.LogWarning("Guest model is not valid."); return(BadRequest()); } var response = await _guestService.CreateAsync(model); if (!response.Result) { _logger.LogError($"An error occured during guest creation."); return(BadRequest(response)); } _logger.LogInformation($"Guest successfully created: {response.Item.Id}"); return(new OkObjectResult(response)); }