Пример #1
0
        public ActionResult Update(UpdateRequestViewModel vm, int RequestID)
        {
            if (vm.QuantityToFulfill > vm.QuantityAvailable || vm.QuantityToFulfill > vm.QuantityRequested)
            {
                vm.ErrorMessage = "Quantity To Fulfill must be less than or equal to the Quantity Requested and Quantity Available";
            }
            else if (ModelState.IsValid)
            {
                string username = Session["Username"].ToString();

                // Ideally the below  2 queries will be done in a transaction

                // Update the request to Closed status with the Fulfilled Quantity
                string sql = String.Format("UPDATE request SET FulfilledQuantity = {0}, Status='Closed' " +
                                           "WHERE RequestID = {1} ;", vm.QuantityToFulfill, RequestID);

                SqlHelper.ExecuteNonQuery(sql);

                // Update the Item Inventory as appropriate
                string sql2 = String.Format("UPDATE item SET NumberOfUnits = (NumberOfUnits - {0}) WHERE ItemID = {1} ;",
                                            vm.QuantityToFulfill, vm.ItemID);

                SqlHelper.ExecuteNonQuery(sql2);

                vm.StatusMessage = "Succesfully completed!!";
                vm.Success       = true;
            }
            return(View(vm));
        }
Пример #2
0
        public async Task <Request> UpdateRequest(Guid requestId, UpdateRequestViewModel viewModel)
        {
            var request = await GetRequestByIdAsync(requestId);

            if (request == null)
            {
                return(null);
            }

            request.Amount = viewModel.Amount;

            try
            {
                //BUG: The user might have multiple request in progress at the same time
                if (!await _shareControlService.HasEnoughShares(request.PortfolioId, request.ShareId, viewModel.Amount))
                {
                    throw new ArgumentException("Owner porfolio doesn't have enough shares");
                }
            }
            catch (Exception e)
            {
                throw new ArgumentException("Something went wrong, try again");
            }

            _unitOfWork.RequestsRepository.Update(request);
            await _unitOfWork.CommitAsync();

            return(request);
        }
Пример #3
0
        public ActionResult Update(int RequestID)
        {
            // Get the logged in Site ID from the session
            int?SiteID = Session["SiteID"] as int?;

            // if there is none, redirect to the login page
            if (!SiteID.HasValue)
            {
                return(RedirectToAction("Login", "Account"));
            }

            UpdateRequestViewModel vm = new UpdateRequestViewModel();

            // get the info on pending request; find out if it can be updated
            string sql = String.Format("SELECT s.SiteName, u.Username, i.ItemName, r.RequestedQuantity as 'RequestedQuantity', i.NumberOfUnits as 'QuantityAvailable', i.SiteID as 'OwnerSiteID', i.ItemID " +
                                       "FROM request r " +
                                       "INNER JOIN item i on i.ItemId = r.ItemID " +
                                       "INNER JOIN user u on r.Username = u.Username " +
                                       "INNER JOIN site s on u.SiteID = s.SiteID " +
                                       "WHERE r.RequestId = {0} AND r.Status='Pending' ;", RequestID.ToString());

            object[] queryResponse = SqlHelper.ExecuteSingleSelect(sql, 7);

            if (queryResponse != null)
            {
                vm.RequestorSiteName = queryResponse[0].ToString();
                vm.RequestorUsername = queryResponse[1].ToString();
                vm.ItemName          = queryResponse[2].ToString();
                vm.QuantityRequested = int.Parse(queryResponse[3].ToString());
                vm.QuantityAvailable = int.Parse(queryResponse[4].ToString());
                vm.OwnerSiteID       = int.Parse(queryResponse[5].ToString());
                vm.ItemID            = int.Parse(queryResponse[6].ToString());
            }
            else
            {
                throw new Exception("No pending request found with RequestID = " + RequestID.ToString());
            }

            // setup the default Quantity to Fulfill
            if (vm.QuantityRequested > vm.QuantityAvailable)
            {
                vm.QuantityToFulfill = vm.QuantityAvailable;
            }
            else
            {
                vm.QuantityToFulfill = vm.QuantityRequested;
            }

            if (vm.OwnerSiteID != SiteID.Value)
            {
                throw new Exception("You cannot update a request that is not for an item in your Site.");
            }

            return(View(vm));
        }
Пример #4
0
        public async Task <IActionResult> UpdateRequest(int id)
        {
            var updateRequestViewModel = new UpdateRequestViewModel();

            updateRequestViewModel.CardRequest = (await _cardRequestService.GetByIdIncludes(id));
            updateRequestViewModel.City        = await _cityRepository.GetByIdAsync(updateRequestViewModel.CardRequest.CityId);

            updateRequestViewModel.CardRequestHistories = await _cardRequestHistoryService.GetAllByRequestIdIncludes(id);

            return(View(updateRequestViewModel));
        }
Пример #5
0
        public ActionResult <AccountResponseViewModel> Update(int id, UpdateRequestViewModel model)
        {
            // users can update their own account and admins can update any account
            if (id != Account.Id && Account.Role != Role.Admin)
            {
                return(Unauthorized(new { message = "Unauthorized" }));
            }

            // only admins can update role
            if (Account.Role != Role.Admin)
            {
                model.Role = null;
            }

            var account = _accountService.UpdateUser(id, model);

            return(Ok(account));
        }
Пример #6
0
        public UpdateRequestPage(Request request)
        {
            InitializeComponent();
            var updateRequestViewModel = new UpdateRequestViewModel();

            updateRequestViewModel.RequestId = request;
            BindingContext = updateRequestViewModel;

            var requestid = request.id;

            MessagingCenter.Send(new PassIdPatient()
            {
                idPatient = requestid
            }, "UpdateRequestId");
            var patientid = request.patient.id;

            MessagingCenter.Send(new PassIdPatient()
            {
                idPatient = patientid
            }, "UpdatePatientId");
            var clientid = request.client.id;

            MessagingCenter.Send(new PassIdPatient()
            {
                idPatient = clientid
            }, "UpdateClientId");

            /* if(request.doctorNoRef == null)
             * {
             *   return;
             * }
             * else
             * {
             *   var doctorNoRefid = request.doctorNoRef.client.id;
             *   MessagingCenter.Send(new PassIdPatient() { idPatient = doctorNoRefid }, "DoctorNoRefId");
             *   Debug.WriteLine("********Id of DoctorRef*************");
             *   Debug.WriteLine(doctorNoRefid);
             * }*/
        }
 public ActionResult Update(UpdateRequestViewModel model)
 {
     if (ModelState.IsValid)
     {
         Request request = new Request
         {
             Id    = model.Id,
             State = model.State
         };
         if (_requestService.Update(request))
         {
             return(RedirectToAction("AllRequests"));
         }
         else
         {
             return(new HttpStatusCodeResult(404));
         }
     }
     else
     {
         return(new HttpStatusCodeResult(404));
     }
 }
Пример #8
0
        public AccountResponseViewModel UpdateUser(int id, UpdateRequestViewModel model)
        {
            var account = _userDataMgr.GetUserById(id);

            // validate
            if (account.Email != model.Email && _userDataMgr.CheckUserEmail(model.Email))
            {
                throw new AppException($"Email '{model.Email}' is already taken");
            }

            // hash password if it was entered
            if (!string.IsNullOrEmpty(model.Password))
            {
                account.PasswordHash = BC.HashPassword(model.Password);
            }

            // copy model to account and save
            _mapper.Map(model, account);
            account.Updated = DateTime.UtcNow;

            _userDataMgr.UpdateUser(account);

            return(_mapper.Map <AccountResponseViewModel>(account));
        }
Пример #9
0
        public async Task <IActionResult> UpdateRequest([FromRoute] Guid requestId, [FromBody] UpdateRequestViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var request = await _traderService.UpdateRequest(requestId, viewModel);

                if (request == null)
                {
                    return(NotFound("request not found"));
                }
                return(Ok(request));
            }
            catch (System.Exception)
            {
                return(BadRequest("Couldn't update model"));

                throw;
            }
        }