public JsonResult GetOrderByOrderNumber(string number) { IOrder foundOrder = orderService.GetOrderByNumber(number); return(Json(foundOrder == null ? "not exists" : WebAssembler.Assemble(foundOrder, ViewBag.Language), JsonRequestBehavior.AllowGet)); }
public JsonResult CreateOrder(CreateOrderData createOrderData) { string userName = User.Identity.IsAuthenticated ? User.Identity.Name : null; orderService.CreateOrder(WebAssembler.Assemble(createOrderData, userName)); return(Json("Ok")); }
public JsonResult GetMostPopularItems() { IEnumerable <IItem> items = itemService.getMostPopularItems(10); IEnumerable <Item> result = WebAssembler.Assemble(items, ViewBag.Language); return(Json(result, JsonRequestBehavior.AllowGet)); }
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)); }
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)); }
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)); }
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")); }
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")); }
public JsonResult GetOrdersByPhonerNumber(string phoneNumber) { IEnumerable <IOrder> foundOrders = orderService.GetOrdersByPhoneNumber(phoneNumber); return(Json(WebAssembler.Assemble(foundOrders, ViewBag.Language), JsonRequestBehavior.AllowGet)); }
public JsonResult GetUserOrders() { IEnumerable <IOrder> foundOrders = orderService.GetOrdersByUser(HttpContext.User.Identity.Name); return(Json(WebAssembler.Assemble(foundOrders, ViewBag.Language), JsonRequestBehavior.AllowGet)); }
public JsonResult ChangePersonalInfo(ChangePersonalInfoData data) { personalInfoService.ChangePersonalInfoData(WebAssembler.Assemble(data, HttpContext.User.Identity.Name)); return(Json("Ok")); }
public JsonResult GetPersonalInfo() { IPersonalInfo info = personalInfoService.GetPersonalInfo(HttpContext.User.Identity.Name); return(Json(WebAssembler.Assemble(info), JsonRequestBehavior.AllowGet)); }