private void Sender(ServiceCode service, string from, string to, string subject, string message) { var messageRequest = new MessageRequestModel() { From = from, To = to, Message = message, Subject = subject, Brand = _xnotifiSettings.Value.Brand }; var gateway = GetGateway(service); gateway.Password = _generator.Decrypt(gateway.Password).Result; var application = GetCreateApplication(_xnotifiSettings.Value.Brand, _xnotifiSettings.Value.ClientId); var messager = (_xnotifiSettings.Value.Development)? "Local Dev." : _messageAdapter.Send(messageRequest, gateway); var requestLog = new RequestModel() { ApplicationId = application.ApplicationId, GatewayId = gateway.GatewayId, Service = ServiceCode.Email, Recipients = 1, Cost = 0.00m, Response = messager, DateCreated = DateTime.UtcNow }; _requestService.Create(requestLog); }
public async Task <RequestModel> Post(CreateRequestModel model) { var result = await _service.Create(model); var models = _mapper.Map <RequestModel>(result); return(models); }
public async Task <RequestModel> Post([FromBody] CreateRequestModel requestModel) { var item = await _service.Create(requestModel); var model = _mapper.Map <RequestModel>(item); return(model); }
public async Task <IActionResult> Join(int teamId) { var user = await _userManager.GetUserAsync(HttpContext.User); if (user.HasATeam()) { return(BadRequest("Bạn phải rời khỏi đội bóng hiện tại trước khi có thể gửi yêu cầu.")); } var request = await _unitOfWork.Requests.GetPendingRequest(user.Id, teamId); if (request != null) { return(BadRequest("Bạn đã gửi yêu cầu tới đội bóng này hoặc đội bóng này đã gửi lời mời gia nhập đến bạn")); } await _requestService.Create(user.Id, teamId, RequestType.FromMember); return(Ok()); }
public async Task <IActionResult> Create([Bind("Id, FirstName, LastName, Email, Comment")] Request request, IFormFile image) { try { await _service.Create(request, image); return(RedirectToAction("Index", "Home")); } catch (Exception e) { ModelState.Merge(_service.ModelState); return(View("Index", request)); } }
/// <summary> /// It links this player to current user. /// </summary> /// <param name="playerId">Player id.</param> /// <returns>Message to user about binding /// Player and User. </returns> public string LinkWithUser(int playerId) { var userId = _currentUserService.GetCurrentUserId(); string message; if (userId != ANONYM) { _requestService.Create(userId, playerId); message = Resources.UI.ViewModelResources.MessageAboutLinkToPlayer; } else { message = Resources.UI.ViewModelResources.MessageAboutError; } return(message); }
public ActionResult <Request> PostRequest(RequestCM model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Request request = new Request(); request = _mapper.Map <Request>(model); _requestService.Create(request); _requestService.Save(); return(StatusCode(201, request.ID)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <ActionResult> Request(Request request) { var eoids = GetEOIDS(); ViewBag.EOIDs = FillDropDown(eoids); var fids = GetFIDS(""); ViewBag.FIDs = FillDropDown(fids); var mids = GetMIDS(""); ViewBag.MIDs = FillDropDown(mids.Items); var products = GetProductsName(""); ViewBag.Products = FillDropDown(products.Items); var countries = GetCountries(); ViewBag.Countries = CountriesFillDropDown(countries.Items); if (ModelState.IsValid) { try { int newMachineId = await _requestService.Create(request); request.Id = request.ToString(); } catch { throw new RequestErrorException("Error creando el Request "); } } return(View("Requests", request)); }
public async Task <ActionResult> FindFirst([FromBody] FindFirstRequest request) { try { if (request.Values.Count() == 0) { return(BadRequest("Empty sequence!")); } var comb = _combinationService.FindFirstCombsWithReps(request.Values, request.Key); var response = await _requestService.Create(request.Values, request.Key, comb); if (response == null || response.Count() == 0) { return(NotFound($"No possible combination of elements in the sequence [{string.Join(", ", request.Values)}] that match key {request.Key}")); } return(Ok(response)); } catch { return(BadRequest($"Ops! Something wrong happened!")); } }
public ActionResult Create(RequestCreateViewModel requestViewModel) { _requestService.Create(ParseCreateViewModelToRequestModel(requestViewModel)); return(RedirectToAction("Index")); }
private MessageResponseModel Messager(MessageRequestModel model) { if (!ModelState.IsValid) { return(new MessageResponseModel() { Error = Data.Enums.MessageStatus.InvalidFields, Message = "Required parameter(s) are missing" }); } if (!model.Service.Equals(ServiceCode.Sms) && !model.Service.Equals(ServiceCode.Email)) { return(new MessageResponseModel() { Error = Data.Enums.MessageStatus.InvalidService, Message = "Invalid service request" }); } var gateway = _gatewayService.List() .FirstOrDefault(x => x.ServiceCode == model.Service && x.IsActive == true); if (gateway == null) { return(new MessageResponseModel() { Error = Data.Enums.MessageStatus.InactiveGateway, Message = "No active gateway available" }); } var client = _clientService.List().ToList().FirstOrDefault(x => x.ClientId.Equals(model.ClientId) && x.AccessKey.Equals(model.AccesssKey) && x.IsActive == true); if (client == null) { return(new MessageResponseModel() { Error = Data.Enums.MessageStatus.InvalidApplication, Message = "No client record is found" }); } var existingApplication = _applicationService.List() .FirstOrDefault(x => x.ClientId == model.ClientId && x.Name.ToLower().Equals(model.AppName.ToLower()) && x.IsActive == true); string applicationId; string applicationName; if (existingApplication == null) { var applicationModel = new ApplicationModel() { ClientId = model.ClientId, Name = model.AppName, DateCreated = DateTime.UtcNow }; var newApplication = _applicationService.Create(applicationModel).Result; applicationId = newApplication.ApplicationId; applicationName = newApplication.Name; } else { applicationId = existingApplication.ApplicationId; applicationName = existingApplication.Name; } var price = (model.Service == ServiceCode.Sms) ? _priceSettings.Value.SmsPrice : _priceSettings.Value.EmailPrice; var destinations = model.To.Split(','); var cost = destinations.Length * price; if (client.Balance < cost) { return(new MessageResponseModel() { Error = Data.Enums.MessageStatus.InsufficientCredit, Message = "Insufficient credit" }); } gateway.Password = _generator.Decrypt(gateway.Password).Result; try { //var gatewayResponse = "local testing"; var gatewayResponse = _messageAdapter.Send(model, gateway); client.Balance = client.Balance - cost; _clientService.Update(client); var request = new RequestModel() { ApplicationId = applicationId, GatewayId = gateway.GatewayId, Recipients = destinations.Length, Cost = cost, Response = gatewayResponse, DateCreated = DateTime.UtcNow }; var lastRequest = _requestService.Create(request).Result; return(new MessageResponseModel() { Error = Data.Enums.MessageStatus.MessageSubmitted, Message = "Message(s) submited successfully", Reference = lastRequest.RequestId }); } catch (Exception e) { Console.WriteLine(e); //throw; } var response = new MessageResponseModel() { Error = Data.Enums.MessageStatus.InternalServerError, Message = "Internal server error" }; return(response); }
public RequestPostResponse Create([FromBody] RequestPostRequest request) { request.UserId = User.GetUserId(); return(_requestService.Create(request)); }
public void Post([FromBody] AddRequest request) { _requestService.Create(request); }