public string HandleAddingPlayerSession(ISession session, IEnumerable <string> tokens) { //TODO: more precise criteria for user's answer if (tokens.Any(t => t == "да")) { _sessionService.UpdateStatus(session.Id, SessionStatus.RequestingName); return("Как вас зовут?"); } else { var currentPlayer = _playerService.GetCurrentPlayer(session.Id); _moveService.Add(new Move { Player = (Player)currentPlayer, PlayerId = currentPlayer.Id, Start = DateTime.Now, }); _sessionService.UpdateStatus(session.Id, SessionStatus.Playing); return($"Начнем игру! {currentPlayer.Name}, вы ходите первым."); } }
public ActionResult Add(Models.Move.AddViewModel model) { if (!ModelState.IsValid) { //select list model.ApplianceSelectList = GetApplianceSelectList(SessionHelper.CurrentUser.UserToken, SessionHelper.CurrentLanguageTwoChar); model.LabSelectList = GetLabSelectList(SessionHelper.CurrentUser.UserToken, SessionHelper.CurrentLanguageTwoChar); return(View(model)); } Business.Models.Move.Move move = new Business.Models.Move.Move(); move.ApplianceId = model.ApplianceId; move.LabId = model.LabId; move.EntranceDate = DateTime.Now; var apiResponseModel = _moveService.Add(SessionHelper.CurrentUser.UserToken, SessionHelper.CurrentLanguageTwoChar, move); if (apiResponseModel.ResultStatusCode == ResultStatusCodeStatic.Success) { return(RedirectToAction(nameof(MoveController.List))); } else { ViewBag.ErrorMessage = apiResponseModel.ResultStatusMessage != null ? apiResponseModel.ResultStatusMessage : "Kaydedilemedi.";//todo: kulturel olacak NotSaved ViewBag.ErrorMessageList = apiResponseModel.ErrorMessageList; //select list model.ApplianceSelectList = GetApplianceSelectList(SessionHelper.CurrentUser.UserToken, SessionHelper.CurrentLanguageTwoChar); model.LabSelectList = GetLabSelectList(SessionHelper.CurrentUser.UserToken, SessionHelper.CurrentLanguageTwoChar); return(View(model)); } }
public IActionResult Add([FromBody] AddRequestModel requestModel, [FromHeader] string displayLanguage) { var responseModel = new ApiResponseModel <Move>(); responseModel.DisplayLanguage = displayLanguage; try { var record = new Move(); record.ApplianceId = requestModel.ApplianceId; record.LabId = requestModel.LabId; record.EntranceDate = requestModel.EntranceDate; record.ExitDate = requestModel.ExitDate; var lab = _labService.GetById(requestModel.LabId); if (lab.CurrentApplianceCapacity + 1 > lab.MaxApplianceCapacity) { responseModel.ResultStatusCode = ResultStatusCodeStatic.Error; responseModel.ResultStatusMessage = "Lab capacity full"; responseModel.Data = null; return(StatusCode(StatusCodes.Status500InternalServerError, responseModel)); } lab.CurrentApplianceCapacity++; _labService.Update(lab); var dbResult = _moveService.Add(record); if (dbResult > 0) { responseModel.Data = record; // oluşturulan entity bilgisinde id kolonu atanmış olur ve entity geri gönderiliyor responseModel.ResultStatusCode = ResultStatusCodeStatic.Success; responseModel.ResultStatusMessage = "Success"; return(Ok(responseModel)); } else { responseModel.ResultStatusCode = ResultStatusCodeStatic.Error; responseModel.ResultStatusMessage = "Could Not Be Saved"; responseModel.Data = null; return(StatusCode(StatusCodes.Status500InternalServerError, responseModel)); } } catch (Exception ex) { responseModel.ResultStatusCode = ResultStatusCodeStatic.Error; responseModel.ResultStatusMessage = ex.Message; responseModel.Data = null; return(StatusCode(StatusCodes.Status500InternalServerError, responseModel)); } }