public IActionResult AddRequest(RequestModel req)
 {
     if (ModelState.IsValid)
     {
         requestService.AddRequest(req);
     }
     return(RedirectToAction("GetMachines", "Machine"));
 }
Esempio n. 2
0
 public IActionResult AddRequest(RequestModel req)
 {
     if (req == null)
     {
         return(BadRequest());
     }
     requestService.AddRequest(req);
     return(RedirectToAction("Index", "Home"));
 }
 public IActionResult AddRequest(RequestModel model)
 {
     if (ModelState.IsValid)
     {
         requestService.AddRequest(model);
         return(RedirectToAction("GetMachines", "Machine"));
     }
     else
     {
         return(BadRequest());
     }
 }
Esempio n. 4
0
        public async Task <IActionResult> AddRequest(AddRequestViewModel viewModel)
        {
            var addRequestDto = _mapper.Map <RequestDto>(viewModel);
            var addRequest    = await _requestService.AddRequest(addRequestDto);

            if (!addRequest.IsValid())
            {
                return(BadRequest(addRequest.Notification));
            }

            var addRequestViewModel = _mapper.Map <AddRequestDto, AddRequestViewModel>(addRequest);

            return(Ok(addRequestViewModel));
        }
Esempio n. 5
0
        public ActionResult Create(CreateRequestModel model)
        {
            var valid     = true;
            var addresses = new List <string>();

            if (model.Errors == null)
            {
                model.Errors = new List <string>();
            }

            if (model.Request.DepartureAddress == "" && model.Request.DeparturePointId == 0)
            {
                model.Errors.Add("Укажите адрес отправления");
                valid = false;
            }

            if (model.Request.DestinationAddress == "" && model.Request.DestinationPointId == 0)
            {
                model.Errors.Add("Укажите адрес назначения");
                valid = false;
            }

            //TODO сделать валидацию даты времени отправления

            if (!valid)
            {
                var poiList = _locationService.GetPOIList();
                model.POIList          = new SelectList(poiList, "Id", "Name");
                model.POIListAddresses = new SelectList(poiList, "Id", "Address");

                return(View(model));
            }

            var    mileageService = new MileageCalculatingService();
            string calcDestinationAddress;
            string calcDepartureAddress;

            if (model.Request.DestinationPointId == 0)
            {
                calcDestinationAddress = model.Request.DestinationAddress;
            }
            else
            {
                calcDestinationAddress = _locationService.GetPOIById(model.Request.DestinationPointId).Address;
            }

            if (model.Request.DeparturePointId == 0)
            {
                calcDepartureAddress = model.Request.DepartureAddress;
            }
            else
            {
                calcDepartureAddress = _locationService.GetPOIById(model.Request.DeparturePointId).Address;
            }

            model.Request.Mileage = mileageService.GetMileage(calcDepartureAddress, calcDestinationAddress);


            model.Request.AuthorLogin = User.Identity.Name;
            var error = "";

            if (!_requestService.AddRequest(model.Request, out error))
            {
                model.Errors.Add(error);
                var poiList = _locationService.GetPOIList();
                model.POIList          = new SelectList(poiList, "Id", "Name");
                model.POIListAddresses = new SelectList(poiList, "Id", "Address");
                return(View(model));
            }

            var userId = _userService.GetUserByMail(HttpContext.User.Identity.Name).Id;

            var newLog = new DtoLog()
            {
                CreatorFirstName = _employeeService.GetUserLastName(userId).Firstname,
                CreatorLastName  = _employeeService.GetUserLastName(userId).Lastname,
                BrowserName      = HttpContext.Request.Browser.Browser,
                IpAddress        = HttpContext.Request.UserHostAddress,
                RequestMile      = model.Request.Mileage,
                RequestPrice     = 10
            };

            _logService.AddLog(newLog, out error);

            return(RedirectToAction("Index", "Request"));
        }
Esempio n. 6
0
 public BasicResponse <RequestInfo> AddRequest(RequestAddRequest requestrequest)
 {
     return(_requestService.AddRequest(requestrequest));
 }
 public IActionResult AddRequest(Requests requests)
 {
     //UserService service = new UserService();
     return(Ok(_requestService.AddRequest(requests)));
 }
        public async Task <IActionResult> AddRequest(DocConfirmRequest docConfirmRequest)
        {
            await _requestService.AddRequest(docConfirmRequest);

            return(Created($"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{HttpContext.Request.Path}", "Запрос успешно создан"));
        }