Esempio n. 1
0
        public ActionResult Details(int id, int?categoryId, bool?newApplications,
                                    bool?myOrders, OrderSorts sort = OrderSorts.New, bool emptyResponse = false)
        {
            var orderDto = _orderService.Find(id);

            if (orderDto == null)
            {
                return(HttpNotFound());
            }

            var clientUser = _userService.FindById(orderDto.UserId);

            var responsesDto = _responseService.GetAllForOrder(id);

            Mapper.Initialize(cfg => cfg.CreateMap <ResponseViewModelBLL, IndexResponseViewModel>()
                              .ForMember("PerformerId", opt => opt.MapFrom(c => c.PerformerId))
                              .ForMember("PerformerName", opt => opt.MapFrom(c => _userService.FindById(c.PerformerId).Surname
                                                                             + " " + _userService.FindById(c.PerformerId).Name))
                              .ForMember("PerformerRating", opt => opt.MapFrom(c => _userService.FindById(c.PerformerId).Rating))
                              .ForMember("Image", opt => opt.MapFrom(c => _userService.FindById(c.PerformerId).PictureId == null
                    ? System.IO.File.ReadAllBytes(Server.MapPath(DefaultImageName))
                    : _pictureService.FindById(_userService.FindById(c.PerformerId).PictureId.Value).Image))
                              );
            var responses = Mapper.Map <IEnumerable <ResponseViewModelBLL>, List <IndexResponseViewModel> >(responsesDto);

            ViewBag.PerformerImage = _userService.FindById(User.Identity.GetUserId <int>())?.PictureId == null
                ? System.IO.File.ReadAllBytes(Server.MapPath(DefaultImageName))
                : _pictureService.FindById(_userService.FindById(User.Identity.GetUserId <int>()).PictureId.Value).Image;

            Mapper.Initialize(cfg => cfg.CreateMap <OrderViewModelBLL, DetailsOrderViewModel>()
                              .ForMember("CustomerId", opt => opt.MapFrom(c => clientUser.Id))
                              .ForMember("CustomerName", opt => opt.MapFrom(c => clientUser.Surname + " " + clientUser.Name))
                              .ForMember("Category", opt => opt.MapFrom(c => _categoryService.FindById(c.CategoryId).Name))
                              .ForMember("Status", opt => opt.MapFrom(c => _statusService.FindById(c.StatusId).Value))
                              .ForMember("Responses", opt => opt.MapFrom(c => responses))
                              .ForMember("Image", opt => opt.MapFrom(c => c.PictureId == null
                ? System.IO.File.ReadAllBytes(Server.MapPath(DefaultImageName))
                : _pictureService.FindById(c.PictureId.Value).Image))
                              );
            DetailsOrderViewModel order = Mapper.Map <OrderViewModelBLL, DetailsOrderViewModel>(orderDto);

            var currentUser = _userService.FindById(User.Identity.GetUserId <int>());

            if (!ReferenceEquals(currentUser, null))
            {
                ViewBag.Rating = currentUser.Rating;
            }
            if (order.StatusId < 4)
            {
                ViewBag.StatusMessage = "Mark as " + _statusService.FindById(order.StatusId + 1).Value;
            }

            ViewBag.CurrentCategoryId = categoryId;
            ViewBag.IsMyOrdersPage    = myOrders;
            ViewBag.IsNewPage         = newApplications;
            ViewBag.ResponseIsEmpty   = emptyResponse;
            ViewBag.Sort = sort;

            return(View(order));
        }
Esempio n. 2
0
        public IActionResult Details(int id)
        {
            DetailsOrderViewModel viewModel = this.orderService.GetOrderById(id)
                                              .To <DetailsOrderViewModel>();

            return(this.View(viewModel));
        }
Esempio n. 3
0
        public IActionResult Details(int id)
        {
            var orderDetails        = this.orders.Details(id);
            var groupedProductsList = this.products.GroupedProducts(orderDetails.ProductQuantities);

            if (orderDetails == null)
            {
                return(this.BadRequest());
            }

            var detailsOrderViewModel = new DetailsOrderViewModel
            {
                Id       = orderDetails.Id,
                Date     = orderDetails.Date,
                Products = groupedProductsList,
            };

            return(this.View(detailsOrderViewModel));
        }
        //GET Delete
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var products = (IEnumerable <Products>)(from p in _db.Products
                                                    join a in _db.DetailsOrders
                                                    on p.Id equals a.ProductId
                                                    where a.OrderId == id
                                                    select p).Include("ProductTypes").Include("SpecialTag");

            DetailsOrderViewModel objDetailsOrderViewModel = new DetailsOrderViewModel()
            {
                Order    = _db.Orders.Include(m => m.User).Where(a => a.Id == id).FirstOrDefault(),
                Users    = _db.AuthenticationUsers.ToList(),
                Products = products.ToList()
            };

            return(View(objDetailsOrderViewModel));
        }
Esempio n. 5
0
        public async Task <IActionResult> Details(int id)
        {
            var orderExists = await _orderService.Exists(id);

            if (!orderExists)
            {
                return(NotFound());
            }

            var order = await _orderService.GetById(id);


            var model = new DetailsOrderViewModel
            {
                Id            = order.Id,
                Date          = order.OrderedDate,
                InvoiceNumber = order.InvoiceNumber,
                Client        = order.Client,
                Products      = await GetProductList()
            };

            return(View(model));
        }
        public async Task <IActionResult> Edit(int id, DetailsOrderViewModel detailsOrderViewModel)
        {
            if (ModelState.IsValid)
            {
                detailsOrderViewModel.Order.OrderDate = detailsOrderViewModel.Order.OrderDate
                                                        .AddHours(detailsOrderViewModel.Order.OrderTime.Hour)
                                                        .AddMinutes(detailsOrderViewModel.Order.OrderTime.Minute);
                var orderDb = _db.Orders.Where(m => m.Id == detailsOrderViewModel.Order.Id).FirstOrDefault();
                orderDb.CustomerName = detailsOrderViewModel.Order.CustomerName;
                if (User.IsInRole(SD.SuperAdminEndUser))
                {
                    orderDb.UserNameId = detailsOrderViewModel.Order.UserNameId;
                }
                orderDb.CustomerPhone = detailsOrderViewModel.Order.CustomerPhone;
                orderDb.Customermail  = detailsOrderViewModel.Order.Customermail;
                orderDb.OrderDate     = detailsOrderViewModel.Order.OrderDate;
                orderDb.IsConfirmed   = detailsOrderViewModel.Order.IsConfirmed;

                await _db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(detailsOrderViewModel));
        }
Esempio n. 7
0
        public async Task <ActionResult> BuyDetails(int?Id)
        {
            if (Id != null)
            {
                var order = _orderService.GetOrder(Id.Value, i => i.Seller, i => i.Middleman, i => i.Buyer, i => i.CurrentStatus, i => i.StatusLogs, i => i.AccountInfos, i => i.Offer, i => i.StatusLogs.Select(m => m.OldStatus), i => i.StatusLogs.Select(m => m.NewStatus));
                if (order != null)
                {
                    if (order.BuyerId == User.Identity.GetUserId())
                    {
                        order.BuyerChecked = true;
                        await _orderService.SaveOrderAsync();

                        var ordersBuy  = _orderService.GetOrders().Where(m => m.BuyerId == User.Identity.GetUserId());
                        var ordersSell = _orderService.GetOrders().Where(m => m.SellerId == User.Identity.GetUserId());
                        ViewData["BuyCount"]  = ordersBuy.Count();
                        ViewData["SellCount"] = ordersSell.Count();
                        DetailsOrderViewModel model = Mapper.Map <Order, DetailsOrderViewModel>(order);

                        var currentStatus = order.CurrentStatus.Value;
                        if (currentStatus == OrderStatuses.BuyerPaying ||
                            currentStatus == OrderStatuses.OrderCreating ||
                            currentStatus == OrderStatuses.MiddlemanFinding ||
                            currentStatus == OrderStatuses.SellerProviding ||
                            currentStatus == OrderStatuses.MidddlemanChecking)
                        {
                            model.ShowCloseButton = true;
                        }
                        if (currentStatus == OrderStatuses.BuyerPaying)
                        {
                            model.ShowPayButton = true;
                        }
                        if ((currentStatus == OrderStatuses.ClosedSuccessfully ||
                             currentStatus == OrderStatuses.PayingToSeller) && !order.BuyerFeedbacked)
                        {
                            model.ShowFeedbackToSeller = true;
                        }
                        if ((currentStatus == OrderStatuses.ClosedSuccessfully ||
                             currentStatus == OrderStatuses.PayingToSeller) && !order.SellerFeedbacked)
                        {
                            model.ShowFeedbackToBuyer = true;
                        }
                        if (currentStatus == OrderStatuses.BuyerConfirming ||
                            currentStatus == OrderStatuses.ClosedSuccessfully ||
                            currentStatus == OrderStatuses.PayingToSeller)
                        {
                            model.ShowAccountInfo = true;
                        }

                        if (currentStatus == OrderStatuses.BuyerConfirming)
                        {
                            model.ShowConfirm = true;
                        }

                        if (currentStatus == OrderStatuses.SellerProviding)
                        {
                            model.ShowProvideData = true;
                        }
                        if (order.Offer.SellerPaysMiddleman)
                        {
                            model.MiddlemanPrice = 0;
                        }
                        else
                        {
                            model.MiddlemanPrice = order.Offer.MiddlemanPrice.Value;
                        }
                        IList <StatusLog> orderLogs = new List <StatusLog>();

                        foreach (var log in order.StatusLogs)
                        {
                            orderLogs.Add(log);
                            if (log.NewStatus.Value == OrderStatuses.AbortedByBuyer)
                            {
                                var test = order.StatusLogs.FirstOrDefault(s => s.NewStatus.Value == OrderStatuses.BuyerConfirming);
                                orderLogs.Remove(test);
                            }
                        }

                        model.Logs = orderLogs;

                        model.CurrentStatusName = order.CurrentStatus.DuringName;
                        model.StatusLogs        = order.StatusLogs;
                        model.ModeratorId       = order.MiddlemanId;
                        return(View(model));
                    }
                    return(RedirectToAction("OrderBuy"));
                }
            }

            return(HttpNotFound());
        }