Пример #1
0
        public JsonResult GetOrderByOrderNumber(string number)
        {
            IOrder foundOrder = orderService.GetOrderByNumber(number);

            return(Json(foundOrder == null ? "not exists" :
                        WebAssembler.Assemble(foundOrder, ViewBag.Language), JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public JsonResult CreateOrder(CreateOrderData createOrderData)
        {
            string userName = User.Identity.IsAuthenticated ? User.Identity.Name : null;

            orderService.CreateOrder(WebAssembler.Assemble(createOrderData, userName));
            return(Json("Ok"));
        }
Пример #3
0
        public JsonResult GetMostPopularItems()
        {
            IEnumerable <IItem> items = itemService.getMostPopularItems(10);

            IEnumerable <Item> result = WebAssembler.Assemble(items, ViewBag.Language);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        public JsonResult GetItems(string category, int countOnPage, int page)
        {
            IItemsData itemsData = itemService.getItemsByCategory(WebAssembler.Assemble(category), countOnPage, page);

            ItemsData result = new ItemsData(itemsData.TotalCount,
                                             WebAssembler.Assemble(itemsData.Items, ViewBag.Language));

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #5
0
        public JsonResult GetOrdersByDateRange(DateTime dateFrom, DateTime dateTo)
        {
            DateTime             utcDateFrom     = dateFrom.ToUniversalTime();
            DateTime             utcDateTo       = dateTo.ToUniversalTime();
            IEnumerable <IOrder> foundOrders     = orderService.GetOrdersByDateRange(utcDateFrom, utcDateTo);
            IEnumerable <Order>  assembledOrders = WebAssembler.Assemble(foundOrders, ViewBag.Language);

            return(Json(assembledOrders, JsonRequestBehavior.AllowGet));
        }
Пример #6
0
        public ActionResult ChangeItem(string code)
        {
            IItem  item    = itemService.getItemByCode(code);
            string ruName  = null;
            string ukrName = null;
            string engName = null;

            foreach (IItemName itemName in item.Names)
            {
                switch (itemName.LanguageType)
                {
                case LanguageType.English:
                    engName = itemName.Name;
                    break;

                case LanguageType.Russian:
                    ruName = itemName.Name;
                    break;

                case LanguageType.Ukrainian:
                    ukrName = itemName.Name;
                    break;

                default:
                    string exceptionMessage = $"Not supported value {itemName.LanguageType.ToString()} of field IItemName.LanguageType";
                    logger.Error(exceptionMessage);
                    throw new NotSupportedException(exceptionMessage);
                }
            }


            IEnumerable <string> itemAdditionalImageNames = ItemUtils.GetItemAdditionalImageNames(code);
            string mainImageName = ItemUtils.getMainImageName(code);


            ChangeItemViewModel viewModel = new ChangeItemViewModel(Guid.NewGuid().ToString(), item.Code, item.Price.ToString(),
                                                                    WebAssembler.Assemble(item.Category), ruName, ukrName, engName, mainImageName, categories, itemAdditionalImageNames);

            return(View(viewModel));
        }
Пример #7
0
        public JsonResult CreateItem(CreateItemData item, string key)
        {
            IBriefItem assembled  = WebAssembler.Assemble(item);
            string     newIteCode = itemService.createItem(assembled);

            DirectoryInfo imagesDirectory = new DirectoryInfo(Server.MapPath(GlobalConstants.ImagesDirectoryPath));

            if (!imagesDirectory.Exists)
            {
                imagesDirectory.Create();
            }

            DirectoryInfo tempItemDirectory = new DirectoryInfo(Server.MapPath(tempFolderPath + key));

            FileInfo[] files = tempItemDirectory.GetFiles();

            foreach (FileInfo file in files)
            {
                if (isFileImage(file))
                {
                    string newName;
                    if (file.Name.Substring(0, file.Name.LastIndexOf('.')) == "Main")
                    {
                        newName = $"{newIteCode}_Main";
                    }
                    else
                    {
                        newName = $"{newIteCode}_{Guid.NewGuid().ToString()}";
                    }

                    newName += WebAssembler.CalcualteFileExtension(file.Name);

                    System.IO.File.Move(file.FullName, Server.MapPath(GlobalConstants.ImagesDirectoryPath + newName));
                }
            }

            tempItemDirectory.Delete(true);
            return(Json("Ok"));
        }
Пример #8
0
        public JsonResult ChangeItem(ChangeItemData itemData, string key)
        {
            IChangeItemData data = new BLL.Entities.ChangeItemData(
                itemData.Code,
                string.IsNullOrEmpty(itemData.NewPrice) ? (decimal?)null : WebAssembler.AssemblePrice(itemData.NewPrice),
                string.IsNullOrEmpty(itemData.NewCategory) ? (BLL.Interfaces.ItemCategory?)null: WebAssembler.Assemble(itemData.NewCategory),
                itemData.NewRuName,
                itemData.NewUkName,
                itemData.NewEnName
                );

            itemService.changeItem(data);

            DirectoryInfo imagesDirectory = new DirectoryInfo(Server.MapPath(GlobalConstants.ImagesDirectoryPath));

            if (itemData.AdditionalImagesToDeleteNames?.Any() == true)
            {
                foreach (FileInfo file in imagesDirectory.GetFiles().Where(file => file.Name.StartsWith($"{itemData.Code}_")))
                {
                    if (itemData.AdditionalImagesToDeleteNames.Contains(file.Name))
                    {
                        file.Delete();
                    }
                }
            }

            if (itemData.IsMainImageChanged || itemData.AreAdditionalImagesAdded)
            {
                DirectoryInfo tempItemDirectory = new DirectoryInfo(Server.MapPath(tempFolderPath + key));

                if (itemData.IsMainImageChanged)
                {
                    FileInfo oldMainImage = imagesDirectory.GetFiles().
                                            First(file => file.Name.Substring(0, file.Name.LastIndexOf('.')) == $"{itemData.Code}_Main");
                    oldMainImage.Delete();
                    FileInfo mainImage = tempItemDirectory.GetFiles().First(file => file.Name.Substring(0, file.Name.LastIndexOf('.')) == "Main");
                    string   newName   = $"{itemData.Code}_Main" + WebAssembler.CalcualteFileExtension(mainImage.Name);
                    System.IO.File.Move(mainImage.FullName, Server.MapPath(GlobalConstants.ImagesDirectoryPath + newName));
                }

                if (itemData.AreAdditionalImagesAdded)
                {
                    foreach (FileInfo file in tempItemDirectory.GetFiles())
                    {
                        if (isFileImage(file))
                        {
                            string newName = $"{itemData.Code}_{Guid.NewGuid().ToString()}" + WebAssembler.CalcualteFileExtension(file.Name);
                            System.IO.File.Move(file.FullName, Server.MapPath(GlobalConstants.ImagesDirectoryPath + newName));
                        }
                    }
                }

                tempItemDirectory.Delete(true);
            }

            return(Json("Ok"));
        }
Пример #9
0
        public JsonResult GetOrdersByPhonerNumber(string phoneNumber)
        {
            IEnumerable <IOrder> foundOrders = orderService.GetOrdersByPhoneNumber(phoneNumber);

            return(Json(WebAssembler.Assemble(foundOrders, ViewBag.Language), JsonRequestBehavior.AllowGet));
        }
Пример #10
0
        public JsonResult GetUserOrders()
        {
            IEnumerable <IOrder> foundOrders = orderService.GetOrdersByUser(HttpContext.User.Identity.Name);

            return(Json(WebAssembler.Assemble(foundOrders, ViewBag.Language), JsonRequestBehavior.AllowGet));
        }
Пример #11
0
 public JsonResult ChangePersonalInfo(ChangePersonalInfoData data)
 {
     personalInfoService.ChangePersonalInfoData(WebAssembler.Assemble(data, HttpContext.User.Identity.Name));
     return(Json("Ok"));
 }
Пример #12
0
        public JsonResult GetPersonalInfo()
        {
            IPersonalInfo info = personalInfoService.GetPersonalInfo(HttpContext.User.Identity.Name);

            return(Json(WebAssembler.Assemble(info), JsonRequestBehavior.AllowGet));
        }