public async Task <IActionResult> Add([FromBody] AddVisitContract contract) { var state = await _service.AddVisit(contract); if (!state.Success) { BadRequest(state.Error); } return(Ok(_mapper.Map <Visit, AddVisitDto>(state.Source))); }
public async Task <ActionResult> CreateVisit([FromBody] VisitDTO visitDTO) { try { visitDTO.UserId = _userService.FindUserByEmail(User.Identity.Name).Id; await _visitService.AddVisit(visitDTO); return(Ok()); } catch (Exception ex) { return(StatusCode(500, $"Internal server error: {ex}")); } }
public async Task <IActionResult> Create([FromBody] AddVisitDto visit) { if (!ModelState.IsValid) { return(BadRequest()); } var response = await _visitService.AddVisit(visit); if (response == null) { return(BadRequest()); } return(Ok(response)); }
public string Execute(IList <string> parameters) { string clientFirstName; string clientLastName; Guid clientId; string companyName; Guid companyId; string sportshallName; Guid sportshallId; string sportName; Guid sportId; try { clientFirstName = parameters[0]; clientLastName = parameters[1]; companyName = parameters[2]; sportshallName = parameters[3]; sportName = parameters[4]; } catch { throw new ArgumentException("Failed to parse AddVisit command parameters."); } Guard.WhenArgument(companyName, "Company name").IsNullOrEmpty().Throw(); companyId = this.clientService.GetCompanyGuidByName(companyName); Guard.WhenArgument(clientFirstName, "Client's first name").IsNullOrEmpty().Throw(); Guard.WhenArgument(clientLastName, "Client's last name").IsNullOrEmpty().Throw(); clientId = this.visitService.GetClientGuidByNamesAndCompanyId(clientFirstName, clientLastName, companyId); Guard.WhenArgument(sportshallName, "Sportshall name").IsNullOrEmpty().Throw(); sportshallId = this.visitService.GetSportshallGuidByName(sportshallName); Guard.WhenArgument(sportName, "Sport name").IsNullOrEmpty().Throw(); sportId = this.visitService.GetSportGuidByName(sportName); IVisitDto visit = this.SportscardFactory.CreateVisitDto(clientId, sportshallId, sportId); visitService.AddVisit(visit); return($"The visit was added to database."); }
public ActionResult Apply(int?id) { Container_Visit conta_visit = null; if (Request.Form != null && Request.Form.Count > 0) { ActionResult ar = base.JudgeResult( visitService.AddVisit(Request, ref conta_visit), () => RedirectToAction("Details", new { curpage = 1, message = "感谢您的参与,稍后红会成员会与您联系" })); if (conta_visit != null && conta_visit.list_err.Count > 0) { ViewData["activity"] = id == null ? 1 : id; return(View(conta_visit)); } else { return(ar); } } ViewData["activity"] = id == null ? 1 : id; return(View()); }
public ActionResult Create(IFormCollection collection) { try { //WALIDACJA if (!hours.Contains(collection["hour"].ToString())) { _logger.LogWarning("User: {login} tried to add visit with invalid hour", GetUserName()); TempData["validationHour"] = _localizer["Choose hour from list"].ToString(); } User visitor, doctor; if (HttpContext.User.IsInRole("Doctor")) { visitor = _userService.GetUserByLogin(collection["visitorLogin"].ToString()); doctor = _userService.GetUserByLogin(GetUserName()); } else { doctor = _userService.GetUserByLogin(collection["docLogin"].ToString()); visitor = _userService.GetUserByLogin(GetUserName()); } //Błędy walidacji if (TempData["validationHour"] != null) { TempData["docLogin"] = collection["docLogin"].ToString(); TempData["date"] = collection["date"].ToString(); TempData["edit"] = collection["edit"].ToString(); if (HttpContext.User.IsInRole("Doctor")) { TempData["visitorLogin"] = collection["visitorLogin"].ToString(); } return(RedirectToAction(nameof(Hour))); } string onlyDate = collection["date"].ToString().Split(" ")[0]; DateTime date = Convert.ToDateTime(onlyDate + (" ") + collection["hour"].ToString() + ":00"); _visitService.AddVisit(new Visit(doctor, visitor, date)); if (!collection["edit"].ToString().Equals("-1")) // znaczy że to była edycja { return(RedirectToAction(nameof(Delete), new { id = collection["edit"] })); } return(RedirectToAction(nameof(Index))); } catch (Microsoft.EntityFrameworkCore.DbUpdateException) { _logger.LogError("User: {login} tried to add visit with reserved term", GetUserName()); TempData["noAdd"] = _localizer["Chosen hour is alredy busy, please select another"].ToString(); TempData["docLogin"] = collection["docLogin"].ToString(); TempData["date"] = collection["date"].ToString(); TempData["edit"] = collection["edit"].ToString(); if (HttpContext.User.IsInRole("Doctor")) { TempData["visitorLogin"] = collection["visitorLogin"].ToString(); } return(RedirectToAction(nameof(Hour))); } }