public ActionResult DeleteConfirmed(int id, bool?isMyOrdersPage, bool?isNewOrdersPage, int?currentCategoryId, OrderSorts ordersSort = OrderSorts.New) { if (User.Identity.GetUserId <int>() != _orderService.Find(id).UserId) { return(View("~/Views/Error/Forbidden.cshtml")); } var responses = _responseService.GetAllForOrder(id); if (responses.Any()) { foreach (var response in responses) { _responseService.Delete(response.Id); } } _orderService.DeleteOrder(id); var picture = _orderService.Find(id).PictureId; if (picture.HasValue) { _pictureService.Delete(picture.Value); } _unitOfWork.Save(); return(RedirectToAction("Index", new { newApplications = isNewOrdersPage, myOrders = isMyOrdersPage, categoryId = currentCategoryId, sort = ordersSort })); }
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)); }
public ActionResult Confirm(int id, int?currentCategoryId, OrderSorts ordersSort) { _orderService.ConfirmOrder(id); _unitOfWork.Save(); return(RedirectToAction("Index", new { newApplications = _orderService.GetAll().Count(o => !o.AdminStatus) > 0, categoryId = currentCategoryId, sort = ordersSort })); }
public ActionResult Reject(int id, int?currentCategoryId, OrderSorts ordersSort) { var pictureId = _userService.FindById(id).PictureId; _orderService.DeleteOrder(id); _pictureService.Delete(pictureId); _unitOfWork.Save(); return(RedirectToAction("Index", new { newApplications = _orderService.GetAll().Count(o => !o.AdminStatus) > 0, categoryId = currentCategoryId, sort = ordersSort })); }
public ActionResult Index(int?page, int?categoryId, string searchName, bool newApplications = false, bool myOrders = false, OrderSorts sort = OrderSorts.New) { var ordersDto = _orderService.GetAll(); if (ordersDto == null) { return(HttpNotFound()); } if (newApplications && !ordersDto.Any(o => !o.AdminStatus)) { ViewBag.AdminMessage = "No new orders"; } ViewBag.NewOrdersAmountString = string.Empty; var newOrdersAmount = ordersDto.Count(model => !model.AdminStatus); if (newOrdersAmount > 0) { ViewBag.NewOrdersAmountString = " + " + newOrdersAmount; } ViewBag.IsNewPage = false; if (newApplications) { ordersDto = ordersDto.Where(model => !model.AdminStatus); ViewBag.IsNewPage = true; } else { ordersDto = ordersDto.Where(model => model.AdminStatus); } ViewBag.IsMyOrdersPage = false; if (myOrders) { ordersDto = _orderService.GetAll(); ordersDto = ordersDto.Where(model => model.UserId == User.Identity.GetUserId <int>()); if (!ordersDto.Any()) { ViewBag.Message = "You have no orders"; } ViewBag.IsMyOrdersPage = true; } ViewBag.ItemsAmount = ordersDto.Count(); var categoriesDto = _categoryService.GetAll().ToList(); var categories = new List <CategoryViewModel>(); foreach (var category in categoriesDto) { categories.Add(new CategoryViewModel() { Id = category.Id, Name = category.Name, ItemsAmount = ordersDto.Count(o => newApplications ? o.AdminStatus != newApplications && o.CategoryId == category.Id : ((myOrders ? o.UserId == User.Identity.GetUserId <int>() : o.AdminStatus) && o.CategoryId == category.Id) ) }); } ViewBag.CategoriesList = categories; if (categoryId != null) { ordersDto = ordersDto.Where(o => o.CategoryId == categoryId); ViewBag.CurrentCategoryId = categoryId; } if (searchName != null) { ordersDto = ordersDto.Where(o => o.Name.ToLower().Contains(searchName.ToLower())); } ViewBag.SearchName = searchName; if (!ordersDto.Any()) { ViewBag.SearchMessage = "No orders found"; } switch (sort) { case OrderSorts.New: ordersDto = ordersDto.OrderByDescending(o => o.UploadDate); break; case OrderSorts.Urgent: ordersDto = ordersDto.OrderBy(o => o.CompletionDate); break; case OrderSorts.Expensive: ordersDto = ordersDto.OrderByDescending(o => o.Price); break; case OrderSorts.Active: ordersDto = ordersDto.OrderBy(o => o.StatusId); break; } ViewBag.Sort = sort; Mapper.Initialize(cfg => cfg.CreateMap <OrderViewModelBLL, IndexOrderViewModel>() .ForMember("Category", opt => opt.MapFrom(c => _categoryService.FindById(c.CategoryId).Name)) .ForMember("Status", opt => opt.MapFrom(c => _statusService.FindById(c.StatusId).Value)) .ForMember("Image", opt => opt.MapFrom(c => c.PictureId == null ? System.IO.File.ReadAllBytes(Server.MapPath(DefaultImageName)) : _pictureService.FindById(c.PictureId.Value).Image)) ); var orders = Mapper.Map <IEnumerable <OrderViewModelBLL>, List <IndexOrderViewModel> >(ordersDto); var orderNames = _orderService.GetAll().Select(o => o.Name).ToArray(); var filteredNames = orderNames.Where(o => o.IndexOf(searchName, StringComparison.InvariantCultureIgnoreCase) >= 0); ViewBag.Names = Json(filteredNames, JsonRequestBehavior.AllowGet); int pageSize = 3; int pageNumber = (page ?? 1); return(View(orders.ToPagedList(pageNumber, pageSize))); }