public async Task PurchaseMovie(PurchaseRequestModel purchaseRequest)
        {
            //Validate Authorization
            // if(_currentUserService.UserId!=purchaseRequest.UserId)
            //     throw new Exception("You are not authorized to purchase the movie!");
            //Check whether the movie is purchased
            if (await IsMoviePurchased(purchaseRequest))
            {
                throw new Exception("The movie has been purchased");
            }
            var movie = await _movieService.GetMovieAsync(purchaseRequest.MovieId);

            purchaseRequest.TotalPrice       = movie.Price;
            purchaseRequest.PurchaseDateTime = DateTime.Now;
            purchaseRequest.PurchaseNumber   = Guid.NewGuid();
            Purchase purchase = new Purchase
            {
                UserId           = purchaseRequest.UserId,
                MovieId          = purchaseRequest.MovieId,
                PurchaseNumber   = purchaseRequest.PurchaseNumber,
                PurchaseDateTime = purchaseRequest.PurchaseDateTime,
                TotalPrice       = purchaseRequest.TotalPrice
            };

            await _purchaseRepository.AddAsync(purchase);
        }
        public async Task PurchaseMovie(PurchaseRequestModel model)
        {
            if (_currentUserService.UserId != model.UserId)
            {
                throw new HttpException(HttpStatusCode.Unauthorized, "You are not Authorized to purchase");
            }

            model.UserId = _currentUserService.UserId;

            // See if Movie is already purchased.
            if (await IsMoviePurchased(model))
            {
                throw new ConflictException("Movie already Purchased");
            }
            // Get Movie Price from Movie Table
            var movie = await _movieService.GetMovieDetailsById(model.MovieId);

            model.TotalPrice = movie.Price;


            //var purchase = _mapper.Map<Purchase>(purchaseRequest);
            var purchase = new Purchase
            {
                UserId           = model.UserId,
                PurchaseNumber   = model.PurchaseNumber,
                TotalPrice       = model.TotalPrice,
                PurchaseDateTime = model.PurchaseDateTime,
                MovieId          = model.MovieId,
            };
            await _purchaseRepository.Add(purchase);
        }
Exemple #3
0
        public async Task PurchaseMovie(PurchaseRequestModel purchaseRequestModel)
        {
            if (_currentLogedInUser.UserId != purchaseRequestModel.UserId)
            {
                throw new Exception("You are not Authorized to purchase");
            }
            if (_currentLogedInUser.UserId != null)
            {
                purchaseRequestModel.UserId = _currentLogedInUser.UserId.Value;
            }

            bool result = await _purchaseRepository.GetExistsAsync(p =>
                                                                   p.UserId == purchaseRequestModel.UserId && p.MovieId == purchaseRequestModel.MovieId);

            if (result)
            {
                throw new Exception("Movie already Purchased");
            }
            var purchase = new Purchase {
                MovieId    = purchaseRequestModel.MovieId,
                UserId     = purchaseRequestModel.UserId,
                TotalPrice = purchaseRequestModel.Price
            };
            await _purchaseRepository.AddAsync(purchase);
        }
        public async Task <UserResponse> PurchaseItem([FromBody] PurchaseRequestModel purchaseRequest)
        {
            /*
             * FLOW:
             *      1. User'ı ve Item'ı göndermeli.
             *      2. User var mı?
             *      3. Item var mı?
             *      4. Ödeme yöntemi nedir? Ona göre hareket edilecek. Kredikartı veya oyun parası. (Bunun için yeni bir modele ihtiyaç var)
             *      5. Ödeme valid ise UserItem tablosuna listedeki Item'lar eklenecek. Ve yeni Item'listesi  ve User değerleri dönmeli.
             */
            /* VALIDATE */
            var validator        = _validatorResolver.Resolve <PurchaseRequestValidator>();
            var validationResult = validator.Validate(purchaseRequest);

            if (!validationResult.IsValid)
            {
                throw new FluentValidation.ValidationException(validationResult.ToString());
            }

            foreach (var item in purchaseRequest.Items)
            {
                var purchaseResponse = await _userItemService.CreateUserItem(item);
            }

            var foundUser = await _userService.GetUserById(purchaseRequest.CustomerId);

            if (foundUser == null)
            {
                throw new NotFoundException(_localizer.GetString(LocaleResourceConstants.UserNotFound));                    //TODO: Handle error logging and response model for client
            }
            return(_mapper.Map <UserResponse>(foundUser));
        }
        public async Task <Tuple <List <HistoryViewModel>, int> > GetHistory(Rm rm)
        {
            PurchaseService      service = new PurchaseService(new BaseRepository <Purchase>(Repository.Db));
            PurchaseRequestModel request = new PurchaseRequestModel("")
            {
                ShopId = rm.ShopId, ParentId = rm.ParentId, Page = -1
            };
            Tuple <List <PurchaseViewModel>, int> result = await service.SearchAsync(request);

            List <HistoryViewModel> viewModels = result.Item1.ConvertAll(x => new HistoryViewModel(x)).ToList();
            var transactionService             = new BaseService <Transaction, TransactionRequestModel, TransactionViewModel>(new BaseRepository <Transaction>(Repository.Db));
            Tuple <List <TransactionViewModel>, int> transactionTuple =
                await transactionService.SearchAsync(
                    new TransactionRequestModel("", "Modified", "False")
            {
                ShopId   = rm.ShopId,
                ParentId = rm.ParentId,
                Page     = -1
            });

            List <HistoryViewModel> models =
                transactionTuple.Item1.ConvertAll(x => new HistoryViewModel(x)
            {
                Type = "Payment", PurchaseId = x.ParentId
            }).ToList();

            viewModels.AddRange(models);
            List <HistoryViewModel> merged = viewModels.OrderByDescending(x => x.Date).ToList();

            return(new Tuple <List <HistoryViewModel>, int>(merged, merged.Count));
        }
Exemple #6
0
        public async Task PurchaseMovie(PurchaseRequestModel purchaseRequest)
        {
            if (_currentUserService.UserId != purchaseRequest.UserId)
            {
                throw new HttpException(HttpStatusCode.Unauthorized, "You are not Authorized to purchase");
            }
            if (_currentUserService.UserId != null)
            {
                purchaseRequest.UserId = _currentUserService.UserId.Value;
            }
            // See if Movie is already purchased.
            if (await IsMoviePurchased(purchaseRequest))
            {
                throw new ConflictException("Movie already Purchased");
            }
            // Get Movie Price from Movie Table
            var movie = await _movieService.GetMovieAsync(purchaseRequest.MovieId);

            purchaseRequest.TotalPrice = movie.Price;

            var purchase = new Purchase()
            {
                UserId           = purchaseRequest.UserId,
                PurchaseNumber   = purchaseRequest.PurchaseNumber,
                TotalPrice       = purchaseRequest.TotalPrice,
                PurchaseDateTime = purchaseRequest.PurchaseDateTime,
                MovieId          = purchaseRequest.MovieId,
            };
            await _purchaseRepository.AddAsync(purchase);
        }
        public async Task <SupplierHistoryViewModel> GetHistoryAsync(string partnerId)
        {
            var purchaseRequest = new PurchaseRequestModel("", "Modified", "True")
            {
                ParentId = partnerId, Page = -1
            };
            var purchaseService = new PurchaseService(new PurchaseRepository(repository.Db));
            ExpenseRequestModel paymentRequest = new ExpenseRequestModel("", "Modified", "True")
            {
                ParentId = partnerId, Page = -1
            };
            var paymentService = new PaymentService(new PaymentRepository(repository.Db));
            List <PurchaseViewModel> purchases = await purchaseService.SearchAsync(purchaseRequest);

            List <ExpenseViewModel> payments = await paymentService.SearchAsync(paymentRequest);

            List <SupplierHistoryDetailViewModel> histories = new List <SupplierHistoryDetailViewModel>();

            histories.AddRange(purchases.ConvertAll(x => new SupplierHistoryDetailViewModel(x)));
            histories.AddRange(payments.ConvertAll(x => new SupplierHistoryDetailViewModel(x)));

            SupplierHistoryViewModel history = new SupplierHistoryViewModel
            {
                Payments      = payments,
                Purchases     = purchases,
                PurchaseTotal = purchases.Sum(x => x.Total),
                PaymentTotal  = payments.Sum(x => x.Amount),
                Histories     = histories.OrderBy(x => x.Created).ToList()
            };

            return(history);
        }
        public async Task <IActionResult> Purchase(PurchaseRequestModel purchaseRequestModel)
        {
            //if (User.Identity.IsAuthenticated == false)
            //{
            //    return RedirectToAction("Login", "Account");
            //}
            //else
            //{
            var movie = await _movieService.GetMovieById(purchaseRequestModel.MovieId);

            purchaseRequestModel.UserId = Convert.ToInt32(HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
            //var checkpurchased = await _userService.CheckPurchased(purchaseRequestModel);
            //if hasn't purchased
            //if (checkpurchased == false)
            //{
            var moviePurchased = await _userService.PurchaseMovie(purchaseRequestModel);

            return(LocalRedirect("~/"));
            //}//if has purchased
            //else
            //{
            //var movieDetails = new MovieDetailsModel
            //{
            //    Movie = movie,
            //    CheckPurchased=checkpurchased
            //};
            //movieDetails.Movie = movie;
            //return View("Views/Movies/Details.cshtml",movieDetails);
            //}


            //}
        }
Exemple #9
0
        public async Task <IActionResult> Purchase(PurchaseRequestModel purchaseRequestModel)
        {
            purchaseRequestModel.UserId = Convert.ToInt32(HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);

            var moviePurchased = await _userService.Purchase(purchaseRequestModel);

            return(LocalRedirect("/"));
        }
Exemple #10
0
        public async Task <IActionResult> Purchases(PurchaseRequestModel purchaseRequestModel)
        {
            //call user service with id and get list of movies that user purchased
            //it should look for cookie is present, cookie should not be expired and get the user id from cookie
            await _userService.PurchaseMovie(purchaseRequestModel);

            return(View());
        }
Exemple #11
0
        //[Authorization]
        public async Task <IActionResult> BuyMovie(PurchaseRequestModel purchaseRequestModel, string returnUrl = null)
        {
            returnUrl ??= Url.Content("~/");
            // call userService to save the movie that will call
            // repository to save in purchase table
            await _userService.PurchaseMovie(purchaseRequestModel);

            return(LocalRedirect(returnUrl));
        }
Exemple #12
0
        public async Task <IActionResult> PurchaseMovie(PurchaseRequestModel purchaseRequest)
        {
            if (ModelState.IsValid)
            {
                var p = _userService.PurchaseMovie(purchaseRequest);
                return(Ok(purchaseRequest));
            }

            return(BadRequest(new { message = "Please correct the input inforrmation" }));
        }
Exemple #13
0
        public async Task <IActionResult> MakePurchase(PurchaseRequestModel model)
        {
            if (ModelState.IsValid)
            {
                var res = await _userService.PurchaseMovie(model);

                return(Ok());
            }
            return(BadRequest("Please check the info you entered"));
        }
        public async Task <ActionResult> CreatePurchase(PurchaseRequestModel purchaseRequest)
        {
            if (ModelState.IsValid)
            {
                await _userService.PurchaseMovie(purchaseRequest);

                return(Ok());
            }
            return(BadRequest(new { message = "please correct the input information" }));
        }
        public ActionResult Edit(PurchaseRequestModel model)
        {
            var purchaseRequest = _purchaseRequestRepository.GetById(model.Id);
            var assignment      = purchaseRequest.Assignment;

            if (ModelState.IsValid)
            {
                purchaseRequest = model.ToEntity(purchaseRequest);

                if (purchaseRequest.IsNew == true)
                {
                    string number = _autoNumberService.GenerateNextAutoNumber(_dateTimeHelper.ConvertToUserTime(DateTime.UtcNow, DateTimeKind.Utc), purchaseRequest);
                    purchaseRequest.Number = number;
                }
                //always set IsNew to false when saving
                purchaseRequest.IsNew = false;
                //copy to Assignment
                if (purchaseRequest.Assignment != null)
                {
                    purchaseRequest.Assignment.Number      = purchaseRequest.Number;
                    purchaseRequest.Assignment.Description = purchaseRequest.Description;
                    purchaseRequest.Assignment.Priority    = purchaseRequest.Priority;
                }

                _purchaseRequestRepository.Update(purchaseRequest);

                //commit all changes in UI
                this._dbContext.SaveChanges();

                //trigger workflow action
                if (!string.IsNullOrEmpty(model.ActionName))
                {
                    WorkflowServiceClient.TriggerWorkflowAction(purchaseRequest.Id, EntityType.PurchaseRequest, assignment.WorkflowDefinitionId, assignment.WorkflowInstanceId,
                                                                assignment.WorkflowVersion.Value, model.ActionName, model.Comment, this._workContext.CurrentUser.Id);
                    //Every time we query twice, because EF is caching entities so it won't get the latest value from DB
                    //We need to detach the specified entity and load it again
                    this._dbContext.Detach(purchaseRequest.Assignment);
                    assignment = _assignmentRepository.GetById(purchaseRequest.AssignmentId);
                }

                //notification
                SuccessNotification(_localizationService.GetResource("Record.Saved"));
                return(Json(new
                {
                    number = purchaseRequest.Number,
                    status = assignment.Name,
                    assignedUsers = assignment.Users.Select(u => u.Name),
                    availableActions = assignment.AvailableActions ?? ""
                }));
            }
            else
            {
                return(Json(new { Errors = ModelState.SerializeErrors() }));
            }
        }
        public IActionResult Purchase(PurchaseRequestModel model)
        {
            //SendMail();
            var po = _dbContext.Bills.Where(w => w.Id == model.PoId).FirstOrDefault();

            po.PurchaseInvoiceNo = model.InvoceNo;
            po.PurchaseDate      = model.InvoceDate ?? DateTime.Now;
            po.GoodReceiveDate   = model.GoodRecordDate ?? DateTime.Now;
            po.Purchase          = 1;
            _dbContext.SaveChanges();
            TempData["success"] = $"Purchase Invoice No:{model.InvoceNo} successfully confirm.";
            return(RedirectToAction("index", "home"));
        }
Exemple #17
0
        public async Task <IActionResult> CreatePurchase(PurchaseRequestModel purchaseRequestModel)
        {
            if (ModelState.IsValid)
            {
                await _userService.PurchaseMovie(purchaseRequestModel);

                return(Ok());
            }
            else
            {
                return(BadRequest(new { Message = "Incorrect purchasing information!" }));
            }
        }
Exemple #18
0
        public async Task <IActionResult> Purchase(PurchaseRequestModel purchaseRequestModel)
        {
            purchaseRequestModel.UserId = Convert.ToInt32(HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);

            await _userService.Purchase(purchaseRequestModel);

            //using (var httpClient=new HttpClient())
            //{
            //    var JsonContent = new StringContent(JsonConvert.SerializeObject(purchaseRequestModel), Encoding.UTF8, "application/json");
            //    await httpClient.PostAsync("http://localhost:50404/api/Purchase", JsonContent);
            //}

            return(LocalRedirect("~/"));
        }
Exemple #19
0
        public async Task <bool> PurchaseMovie(PurchaseRequestModel purchaseRequestModel)
        {
            var purchase = new Purchase
            {
                MovieId          = purchaseRequestModel.MovieId,
                UserId           = purchaseRequestModel.UserId,
                TotalPrice       = purchaseRequestModel.Price,
                PurchaseDateTime = DateTime.Now,
                PurchaseNumber   = Guid.NewGuid()
            };

            var createdPurchase = await _purchaseRepository.AddAsync(purchase);

            return(createdPurchase != null);
        }
Exemple #20
0
        public async Task <Purchase> PurchaseMovie(PurchaseRequestModel purchaseRequestModel)
        {
            var movie = await _movieService.GetMovieById(purchaseRequestModel.MovieId);

            var p = new Purchase
            {
                UserId           = purchaseRequestModel.UserId,
                PurchaseNumber   = purchaseRequestModel.PurchaseNumber.Value,
                TotalPrice       = movie.Price.Value,
                MovieId          = purchaseRequestModel.MovieId,
                PurchaseDateTime = purchaseRequestModel.PurchaseDate.Value
            };

            return(await _purchaseRepository.AddAsync(p));
        }
Exemple #21
0
        public async Task PurchaseMovie(PurchaseRequestModel purchaseRequest)
        {
            var purchased = new Purchase
            {
                UserId           = purchaseRequest.userId,
                PurchaseNumber   = purchaseRequest.purchaseNumber,
                TotalPrice       = (decimal)purchaseRequest.totalPrice,
                PurchaseDateTime = purchaseRequest.purchaseDateTime,
                MovieId          = purchaseRequest.movieId
            };

            var createdPurchased = await _purchaseRepository.AddAsync(purchased);

            Console.WriteLine("Success add purchased movies");
        }
Exemple #22
0
        public async Task <Purchase> PurchaseMovie(PurchaseRequestModel purchaseRequest)
        {
            var purchase = new Purchase();

            PropertyCopy.Copy(purchase, purchaseRequest);

            var movie = await _movieRepository.GetByIdAsync(purchase.MovieId);

            var user = await _userRepository.GetByIdAsync(purchase.UserId);

            purchase.Movie = movie;
            purchase.User  = user;
            //purchase.Id = null;
            return(await _purchaseRepo.AddAsync(purchase));
        }
Exemple #23
0
        //[Authorization]
        public async Task <IActionResult> BuyMovie(int id)
        {
            // call userService to save the movie that will call
            // repository to save in purchase table
            var movie = await _movieService.GetMovieById(id);

            PurchaseRequestModel purchaseRequestModel = new PurchaseRequestModel
            {
                MovieId = movie.Id,
                Price   = movie.Price,
                Title   = movie.Title,
                PostUrl = movie.PosterUrl
            };

            return(View(purchaseRequestModel));
        }
Exemple #24
0
 public async Task PurchaseMovie(PurchaseRequestModel purchaseRequest)
 {
     /*
      * if (_currentUserService.UserId != purchaseRequest.UserId)
      *  throw new HttpException(HttpStatusCode.Unauthorized, "You are not Authorized to purchase");
      * if (_currentUserService.UserId != null) purchaseRequest.UserId = _currentUserService.UserId.Value;
      * // See if Movie is already purchased.
      * if (await IsMoviePurchased(purchaseRequest))
      *  throw new ConflictException("Movie already Purchased");
      * // Get Movie Price from Movie Table
      * var movie = await _movieService.GetMovieAsync(purchaseRequest.MovieId);
      * purchaseRequest.TotalPrice = movie.Price;
      *
      * var purchase = _mapper.Map<Purchase>(purchaseRequest);
      * await _purchaseRepository.AddAsync(purchase);
      */
 }
        public JsonResult CreateOrEditPurchaseRequest(PurchaseRequestModel _purchaserequest, List <PurchaseRequestDetailModel> purchaserequestDetailModels)
        {
            if (Session["UserLogon"] != null)
            {
                _purchaserequest.Account = (AccountModel)Session["UserLogon"];
            }
            _purchaserequest.Id = Convert.ToInt32(_purchaserequest.Id) > 0 ? _purchaserequest.Id : 0;
            var gudangid = _unitOfWork.GudangRepository.Query(a => a.ClinicId == _purchaserequest.Account.ClinicID).Select(x => x.id).FirstOrDefault();

            _purchaserequest.GudangId = gudangid > 0 ? gudangid : 0;
            var request = new PurchaseRequestRequest
            {
                Data = _purchaserequest
            };

            PurchaseRequestResponse _response = new PurchaseRequestResponse();

            new PurchaseRequestValidator(_unitOfWork).Validate(request, out _response);
            if (purchaserequestDetailModels != null)
            {
                foreach (var item in purchaserequestDetailModels)
                {
                    var purchaserequestdetailrequest = new PurchaseRequestDetailRequest
                    {
                        Data = item
                    };
                    purchaserequestdetailrequest.Data.PurchaseRequestId = Convert.ToInt32(_response.Entity.Id);
                    purchaserequestdetailrequest.Data.Account           = (AccountModel)Session["UserLogon"];
                    //
                    var requestnamabarang = new ProductRequest
                    {
                        Data = new ProductModel
                        {
                            Id = Convert.ToInt32(item.ProductId)
                        }
                    };

                    ProductResponse namabarang = new ProductHandler(_unitOfWork).GetDetail(requestnamabarang);
                    purchaserequestdetailrequest.Data.namabarang = namabarang.Entity.Name;
                    PurchaseRequestDetailResponse _purchaserequestdetailresponse = new PurchaseRequestDetailResponse();
                    new PurchaseRequestDetailValidator(_unitOfWork).Validate(purchaserequestdetailrequest, out _purchaserequestdetailresponse);
                }
            }
            return(Json(new { data = _response.Data }, JsonRequestBehavior.AllowGet));
        }
Exemple #26
0
        public async Task PurchaseMovie(PurchaseRequestModel purchaseRequest)
        {
            if (await IsMoviePurchased(purchaseRequest))
            {
                throw new Exception("Movie already Purchased");
            }
            // Get Movie Price from Movie Table
            var movie = await _movieService.GetMovieAsync(purchaseRequest.MovieId);

            purchaseRequest.TotalPrice = movie.Price;

            var purchase = new Purchase
            {
                UserId  = purchaseRequest.UserId,
                MovieId = purchaseRequest.MovieId
            };
            await _purchaseRepository.AddAsync(purchase);
        }
Exemple #27
0
        public async Task PurchaseMovie(PurchaseRequestModel purchaseRequest)
        {
            var movie = await _purchaseRepository.GetByIdAsync(purchaseRequest.MovieId);

            //var user = await _purchaseRepository.GetByIdAsync(purchaseRequest.UserId);
            purchaseRequest.TotalPrice       = movie.TotalPrice;
            purchaseRequest.PurchaseNumber   = movie.PurchaseNumber;
            purchaseRequest.PurchaseDateTime = movie.PurchaseDateTime;
            var purchase = new Purchase
            {
                UserId           = purchaseRequest.UserId,
                MovieId          = purchaseRequest.MovieId,
                TotalPrice       = purchaseRequest.TotalPrice,
                PurchaseNumber   = purchaseRequest.PurchaseNumber,
                PurchaseDateTime = purchaseRequest.PurchaseDateTime
            };
            await _purchaseRepository.AddAsync(purchase);
        }
Exemple #28
0
        // call UserService to save this movie, which is calling UserRepository that will save it to the purchase table
        public async Task <IActionResult> Buy(PurchaseRequestModel purchaseRequestModel)
        {
            try
            {
                int  userId = _currentLogedInUser.UserId;
                bool result = await _userService.PurchaseMovie(purchaseRequestModel);

                if (result)
                {
                    return(View("PurchaseSuccess"));
                }
                return(View("PurchaseFail"));
            }
            catch
            {
                return(View("PurchaseFail"));
            }
        }
Exemple #29
0
        public async Task PurchaseMovie(PurchaseRequestModel purchaseRequest)
        {
            if (_currentUserService.UserId != purchaseRequest.UserId)
            {
                throw new HttpException(HttpStatusCode.Unauthorized, "You are not Authorized to purchase");
            }

            if (await IsMoviePurchased(purchaseRequest))
            {
                throw new ConflictException("Movie already Favorited");
            }
            // Get Movie Price from Movie Table
            var movie = await _movieService.GetMovieByIdAsync(purchaseRequest.MovieId);

            purchaseRequest.TotalPrice = movie.Price;

            var purchase = _mapper.Map <Purchase>(purchaseRequest);
            await _purchaseRepository.AddAsync(purchase);
        }
Exemple #30
0
        public async Task <IActionResult> InitPurchase([FromBody] PurchaseRequestModel model)
        {
            var user = await _dbContext.GetCurrentUserAsync(User);

            if (user == null)
            {
                return(NotFound());
            }

            if (string.IsNullOrEmpty(user.Wallet) || !await _contract.CheckWhitelistAsync(user.Wallet))
            {
                return(BadRequest(new { error = "Not in whitelist" }));
            }
            var rate = await GetRateAsync(model.Count);

            var fixRate = await _contract.SetRateForTransactionAsync(rate.rate, user.Wallet, rate.amount);

            return(Ok(new { amount = UnitConversion.Convert.FromWei(fixRate.Amount), fixRate }));
        }