public void AddPhoto_ValidFormFile_DoesNotThrows() { using (var stream = File.OpenRead(@"./Images/valid-image.jpg")) { var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(@"./Images/valid-image.jpg")) { Headers = new HeaderDictionary(), ContentType = GetContentType(Path.GetFileName(@"./Images/valid-image.jpg")) }; Assert.DoesNotThrowAsync(async() => await _photoService.AddPhoto(file)); } }
private void ProcessProductFoto(int productId, string photoPath) { if (File.Exists(photoPath)) { var tempName = PhotoService.AddPhoto(new Photo(0, productId, PhotoType.Product) { OriginName = photoPath.Split('/').Last() }); if (string.IsNullOrWhiteSpace(tempName)) { try { using (var image = Image.FromFile(photoPath)) { FileHelpers.SaveProductImageUseCompress(tempName, image); if (!string.IsNullOrWhiteSpace(tempName)) { FileHelpers.SaveProductImageUseCompress(tempName, image); } } File.Delete(photoPath); } catch (Exception ex) { Debug.LogError(ex); } } } }
private int CreateMenuItem() { ValidateData(); var mItem = new AdvMenuItem { MenuItemName = txtName.Text, MenuItemParentID = string.IsNullOrEmpty(hParent.Value) ? 0 : Convert.ToInt32(hParent.Value), MenuItemUrlPath = txtUrl.Text, Enabled = ckbEnabled.Checked, Blank = ckbBlank.Checked, SortOrder = Convert.ToInt32(txtSortOrder.Text), MenuItemUrlType = (EMenuItemUrlType)Convert.ToInt32(rblLinkType.SelectedValue), ShowMode = (EMenuItemShowMode)Convert.ToInt32(ddlShowMode.SelectedValue) }; if (_type == MenuService.EMenuType.Top) { CacheManager.RemoveByPattern(CacheNames.GetMainMenuCacheObjectName()); CacheManager.RemoveByPattern(CacheNames.GetMainMenuAuthCacheObjectName()); } else if (_type == MenuService.EMenuType.Bottom) { var cacheName = CacheNames.GetBottomMenuCacheObjectName(); if (CacheManager.Contains(cacheName)) { CacheManager.Remove(cacheName); } var cacheAuthName = CacheNames.GetBottomMenuAuthCacheObjectName(); if (CacheManager.Contains(cacheAuthName)) { CacheManager.Remove(cacheAuthName); } } mItem.MenuItemID = MenuService.AddMenuItem(mItem, _type); _menuItemId = mItem.MenuItemID; if (IconFileUpload.HasFile) { using (IconFileUpload.FileContent) { var tempName = PhotoService.AddPhoto(new Photo(0, _menuItemId, PhotoType.MenuIcon) { OriginName = IconFileUpload.FileName }); if (!string.IsNullOrWhiteSpace(tempName)) { IconFileUpload.SaveAs(FoldersHelper.GetPathAbsolut(FolderType.MenuIcons, tempName)); } } } else { mItem.MenuItemIcon = string.Empty; } MenuService.UpdateMenuItem(mItem, _type); return(mItem.MenuItemID); }
protected void btnUpload_Click(object sender, EventArgs e) { if (!fuIcon.HasFile) { return; } if (!FileHelpers.CheckFileExtension(fuIcon.FileName, FileHelpers.eAdvantShopFileTypes.Image)) { OnErr(new ErrorEventArgs { Message = Resource.Admin_ErrorMessage_WrongImageExtension }); return; } PhotoService.DeletePhotos(PaymentMethodID, PhotoType.Payment); var tempName = PhotoService.AddPhoto(new Photo(0, PaymentMethodID, PhotoType.Payment) { OriginName = fuIcon.FileName }); if (string.IsNullOrWhiteSpace(tempName)) { return; } using (System.Drawing.Image image = System.Drawing.Image.FromStream(fuIcon.FileContent)) { FileHelpers.SaveResizePhotoFile(FoldersHelper.GetPathAbsolut(FolderType.PaymentLogo, tempName), SettingsPictureSize.PaymentIconWidth, SettingsPictureSize.PaymentIconHeight, image); } imgIcon.ImageUrl = FoldersHelper.GetPath(FolderType.PaymentLogo, tempName, true); imgIcon.Visible = true; }
public HttpResponseMessage AddPhoto(Photo photo) { int rowAffected = _service.AddPhoto(photo); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, rowAffected); return(response); }
public void AddPhoto_PassValidData_CallsAddAndSaves() { var photoBll = new UserPhotoBLL(); var unitOfWork = new Mock <IPhotoUnitOfWork>(); var userProfile = new UserProfile { Photos = new List <UserPhoto> { new UserPhoto() } }; unitOfWork.Setup(u => u.UserRepository.Get(It.IsAny <string>())) .Returns(userProfile); unitOfWork.Setup(u => u.UserRepository.Find(It.IsAny <Expression <Func <UserProfile, bool> > >())) .Returns(new List <UserProfile> { new UserProfile() }); unitOfWork.Setup(u => u.Photos.Add(It.IsAny <UserPhoto>())) .Callback <UserPhoto>(t => userProfile.Photos.Add(t)); // Act var photoService = new PhotoService(unitOfWork.Object); photoService.AddPhoto(photoBll); // Assert unitOfWork.Verify(u => u.Photos.Add(It.IsAny <UserPhoto>()), Times.Once()); unitOfWork.Verify(u => u.SaveAsync(), Times.Once()); Assert.IsTrue(userProfile.Photos.Count == 2); }
public void AddPhoto() { mockPhotoRepository.Setup(x => x.Add(It.IsAny <Photo>())).Returns(photo); var photoService = new PhotoService(mockPhotoRepository.Object); Photo photoReturn = photoService.AddPhoto(photo); Assert.AreEqual(photoReturn.Author, "Phongtv"); }
/// <summary> /// /// </summary> /// <param name="photoids">tradelr photo id</param> /// <returns>trademe photo id</returns> private IEnumerable <int> UploadPhotos(IEnumerable <string> photoids) { var ids = photoids.Select(long.Parse); const int timeout = 10000; // 10 seconds var cts = new CancellationTokenSource(); var tasks = new List <Task>(); var results = new List <int>(); var photoservice = new PhotoService(key, secret); using (var t = new Timer(_ => cts.Cancel(), null, timeout, -1)) { foreach (var photoid in ids) { var task = Task.Factory.StartNew(() => { using (var repository = new TradelrRepository()) { var image = repository.GetProductImage(photoid); if (image != null) { if (image.trademephotoid.HasValue) { results.Add(image.trademephotoid.Value); } else { // we need to upload photo var photoreq = new PhotoUploadRequest { FileName = Path.GetFileName(image.url), FileType = Path.GetExtension(image.url).Substring(1), IsWaterMarked = true, IsUsernameAdded = true, PhotoData = Img.ConvertToBase64String(GeneralConstants.APP_ROOT_DIR + image.url) }; photoreq.GenerateSignature(); var resp = photoservice.AddPhoto(new AddPhotoRequest(photoreq)); if (resp.AddPhotoResult.Status == PhotoStatus.Success) { results.Add(resp.AddPhotoResult.PhotoId); image.trademephotoid = resp.AddPhotoResult.PhotoId; repository.Save(); } } } } }, cts.Token); tasks.Add(task); } } Task.WaitAll(tasks.ToArray()); return(results.ToArray()); }
private void SaveNews() { MsgErr(true); // Clean try { var news = new NewsItem { NewsID = NewsId, AddingDate = SQLDataHelper.GetDateTime(txtDate.Text + " " + txtTime.Text), Title = txtTitle.Text, //Picture = file, TextToPublication = FCKTextToPublication.Text, TextAnnotation = CKEditorControlAnnatation.Text, TextToEmail = string.Empty,//rbNo.Checked ? String.Empty : FCKTextToEmail.Text, NewsCategoryID = dboNewsCategory.SelectedValue.TryParseInt(), ShowOnMainPage = chkOnMainPage.Checked, UrlPath = txtStringID.Text, //MetaId = SQLDataHelper.GetInt(hfMetaId.Text), Meta = new MetaInfo { ObjId = NewsId, Title = txtHeadTitle.Text, H1 = txtH1.Text, MetaKeywords = txtMetaKeys.Text, MetaDescription = txtMetaDescription.Text, Type = MetaType.News } }; news.UrlPath = txtStringID.Text; NewsService.UpdateNews(news); if (FileUpload1.HasFile) { if (!FileHelpers.CheckFileExtension(FileUpload1.FileName, FileHelpers.eAdvantShopFileTypes.Image)) { MsgErr(Resource.Admin_ErrorMessage_WrongImageExtension); return; } PhotoService.DeletePhotos(NewsId, PhotoType.News); var tempName = PhotoService.AddPhoto(new Photo(0, NewsId, PhotoType.News) { OriginName = FileUpload1.FileName }); if (!string.IsNullOrWhiteSpace(tempName)) { using (var image = Image.FromStream(FileUpload1.FileContent)) FileHelpers.SaveResizePhotoFile(FoldersHelper.GetPathAbsolut(FolderType.News, tempName), SettingsPictureSize.NewsImageWidth, SettingsPictureSize.NewsImageHeight, image); } } } catch (Exception ex) { MsgErr(ex.Message + " SaveNews main"); Debug.LogError(ex); } }
protected void CreateBrand() { try { var brand = new Brand { Name = txtName.Text, //BrandLogo = logo, Description = FCKDescription.Text, BriefDescription = FCKBriefDescription.Text, Enabled = chkEnabled.Checked, UrlPath = txtURL.Text, SortOrder = txtSortOrder.Text.TryParseInt(), CountryId = SQLDataHelper.GetInt(ddlCountry.SelectedValue), BrandSiteUrl = txtBrandSiteUrl.Text, Meta = new MetaInfo { Type = MetaType.Brand, MetaDescription = txtMetaDescription.Text, Title = txtHeadTitle.Text, MetaKeywords = txtMetaKeys.Text, H1 = txtH1.Text } }; var tempbrandId = BrandService.AddBrand(brand); if (FileUpload1.HasFile) { var tempName = PhotoService.AddPhoto(new Photo(0, tempbrandId, PhotoType.Brand) { OriginName = FileUpload1.FileName }); if (!string.IsNullOrWhiteSpace(tempName)) { using (Image image = Image.FromStream(FileUpload1.FileContent)) { FileHelpers.SaveResizePhotoFile(FoldersHelper.GetPathAbsolut(FolderType.BrandLogo, tempName), SettingsPictureSize.BrandLogoWidth, SettingsPictureSize.BrandLogoHeight, image); } } } if (lblError.Visible == false) { txtName.Text = string.Empty; FCKDescription.Text = string.Empty; FCKBriefDescription.Text = string.Empty; chkEnabled.Checked = true; } // close } catch (Exception ex) { MsgErr(ex.Message + " CreateBrand main"); Debug.LogError(ex); } }
public IActionResult PostPic([FromBody] PhotoDTO pic) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _pService.AddPhoto(pic); return(Ok()); }
protected void bthAddCarousel_Click(object sender, EventArgs e) { lblErrorImage.Text = string.Empty; int sort; if (!CarouselLoad.HasFile) { ulValidationFailed.Visible = true; ulValidationFailed.InnerHtml += string.Format("<li>{0}</li>", Resource.Client_Feedback_WrongData); return; } if (CarouselLoad.HasFile && !FileHelpers.CheckImageExtension(CarouselLoad.FileName)) { lblErrorImage.Text = Resource.Admin_ErrorMessage_WrongImageExtension; return; } int.TryParse(txtSortedCarousel.Text, out sort); if (string.IsNullOrEmpty(txtURL.Text)) { txtURL.Text = "#"; } var carousel = new Carousel { URL = txtURL.Text, SortOrder = sort, Enabled = true }; int id = CarouselService.AddCarousel(carousel); try { if (CarouselLoad.HasFile) { var tempName = PhotoService.AddPhoto(new Photo(0, id, PhotoType.Carousel) { OriginName = CarouselLoad.FileName }); if (!string.IsNullOrWhiteSpace(tempName)) { using (System.Drawing.Image image = System.Drawing.Image.FromStream(CarouselLoad.PostedFile.InputStream)) { FileHelpers.SaveResizePhotoFile(FoldersHelper.GetPathAbsolut(FolderType.Carousel, tempName), SettingsPictureSize.CarouselBigWidth, SettingsPictureSize.CarouselBigHeight, image); } } } } catch (Exception ex) { Debug.LogError(ex, "Attempt to load not image file"); } txtURL.Text = string.Empty; txtSortedCarousel.Text = string.Empty; Response.Redirect(UrlService.GetAdminAbsoluteLink("Carousel.aspx")); }
private void CreateNews() { MsgErr(true); // Clean try { //const string format = "yyyy-MM-dd"; var news = new NewsItem { AddingDate = Convert.ToDateTime(txtDate.Text + " " + txtTime.Text), Title = txtTitle.Text, //Picture = file, TextToPublication = FCKTextToPublication.Text, TextAnnotation = CKEditorControlAnnatation.Text, TextToEmail = String.Empty, NewsCategoryID = dboNewsCategory.SelectedValue.TryParseInt(), ShowOnMainPage = chkOnMainPage.Checked, UrlPath = txtStringID.Text, Meta = new MetaInfo { MetaDescription = txtMetaDescription.Text, Title = txtHeadTitle.Text, MetaKeywords = txtMetaKeys.Text } }; var id = NewsService.InsertNews(news); if (FileUpload1.HasFile) { var tempName = PhotoService.AddPhoto(new Photo(0, id, PhotoType.News) { OriginName = FileUpload1.FileName }); if (!string.IsNullOrWhiteSpace(tempName)) { using (Image image = Image.FromStream(FileUpload1.FileContent)) FileHelpers.SaveResizePhotoFile(FoldersHelper.GetPathAbsolut(FolderType.News, tempName), SettingsPictureSize.NewsImageWidth, SettingsPictureSize.NewsImageHeight, image); } } SendNews(); if (lblError.Visible == false) { txtTitle.Text = string.Empty; FCKTextToPublication.Text = string.Empty; //FCKTextToEmail.Text = string.Empty; rbToAll.Checked = true; } // close } catch (Exception ex) { MsgErr(ex.Message + " CreateNews main"); Debug.LogError(ex); } }
public ActionResult UploadPhotos(HttpPostedFileBase file, PhotoDTO photo) { //var extension = file.FileName.Substring(file.ToString().IndexOf(".")); var fileName = Path.Combine(("/Uploads"), (DateTime.Now.Ticks.ToString() + file.FileName)); file.SaveAs(fileName); _service.AddPhoto(photo, fileName); return(RedirectToAction("Index", "Albums")); }
protected void SaveBrand() { try { var brand = new Brand { BrandId = BrandId, Name = txtName.Text.Trim(), //BrandLogo = logo, Description = FCKDescription.Text, BriefDescription = FCKBriefDescription.Text, Enabled = chkEnabled.Checked, UrlPath = txtURL.Text.Trim(), SortOrder = txtSortOrder.Text.TryParseInt(), CountryId = Convert.ToInt32(ddlCountry.SelectedValue), BrandSiteUrl = txtBrandSiteUrl.Text, Meta = new MetaInfo { ObjId = BrandId, Type = MetaType.Brand, Title = txtHeadTitle.Text, MetaKeywords = txtMetaKeys.Text, MetaDescription = txtMetaDescription.Text }, }; BrandService.UpdateBrand(brand); if (FileUpload1.HasFile) { PhotoService.DeletePhotos(BrandId, PhotoType.Brand); var tempName = PhotoService.AddPhoto(new Photo(0, BrandId, PhotoType.Brand) { OriginName = FileUpload1.FileName }); if (!string.IsNullOrWhiteSpace(tempName)) { using (var image = Image.FromStream(FileUpload1.FileContent)) { FileHelpers.SaveResizePhotoFile(FoldersHelper.GetPathAbsolut(FolderType.BrandLogo, tempName), SettingsPictureSize.BrandLogoWidth, SettingsPictureSize.BrandLogoHeight, image); } } } } catch (Exception ex) { MsgErr(ex.Message + " SaveBrand main"); Debug.LogError(ex); } }
private void SetImage() { int width = Resources.DisplayMetrics.WidthPixels; int height = Resources.DisplayMetrics.HeightPixels; Photo newPhoto = new Photo() { Path = CameraHelper.file.Path, DateOfPublication = DateTime.Now.ToLongDateString(), Author = UserService.GetCurrentUserName() }; _imageView.SetImageBitmap(BitmapHelpers.LoadAndResizeBitmap(CameraHelper.file.Path, width, height)); PhotoService.AddPhoto(newPhoto); GC.Collect(); }
public ActionResult CreatePhoto(Photo photo, IEnumerable <HttpPostedFileBase> files) { if (!ModelState.IsValid) { return(View(photo)); } if (files.Count() == 0 || files.FirstOrDefault() == null) { ViewBag.error = "Please choose a file"; return(View(photo)); } var model = new Photo(); foreach (var file in files) { if (file.ContentLength == 0) { continue; } var fileName = Guid.NewGuid().ToString(); var extension = System.IO.Path.GetExtension(file.FileName).ToLower(); using (var img = System.Drawing.Image.FromStream(file.InputStream)) { model.Path = String.Format("/Images/{0}{1}", fileName, extension); // Save large size image, 800 x 800 SaveToFolder(img, fileName, extension, new Size(220, 220), model.Path); } // Save record to database var photoService = new PhotoService(myDbContext); var userService = new UserService(myDbContext); var user = userService.GetUser(User.Identity.GetUserId()); photoService.AddPhoto(model); userService.UpdateUser(user, model); UpdateUsersCommentPhoto(model.Path); } return(RedirectPermanent("/home")); }
public ActionResult CreateNewEvent(EventViewModel eventViewModel) { if (ModelState.IsValid) { var photoService = new PhotoService(myDbContext); var eventService = new EventService(myDbContext); var eventListService = new EventListService(myDbContext); var userService = new UserService(myDbContext); var e = new Event(); e.Name = eventViewModel.name; e.Creator = userService.GetUser(User.Identity.GetUserId()); e.Description = eventViewModel.description; e.SignupStart = eventViewModel.SignupStart; e.SignupEnd = eventViewModel.SignupEnd; e.StartTime = eventViewModel.StartTime; e.EndTime = eventViewModel.EndTime; e.MaxCapacity = eventViewModel.MaxCapacity; Photo p = new Photo(); p.Path = eventViewModel.photoPath; e.Photo = p; EventList el = new EventList(); el.User = e.Creator; el.Event = e; el.JoinTime = DateTime.Now; photoService.AddPhoto(p); eventService.AddEvent(e); eventListService.AddEventToList(el); return(RedirectToAction("ViewAllEvents")); } else { return(View(eventViewModel)); } }
protected void btnUpload_Click(object sender, EventArgs e) { if (fuIcon.HasFile) { PhotoService.DeletePhotos(PaymentMethodID, PhotoType.Payment); var tempName = PhotoService.AddPhoto(new Photo(0, PaymentMethodID, PhotoType.Payment) { OriginName = fuIcon.FileName }); if (!string.IsNullOrWhiteSpace(tempName)) { using (System.Drawing.Image image = System.Drawing.Image.FromStream(fuIcon.FileContent)) { FileHelpers.SaveResizePhotoFile(FoldersHelper.GetPathAbsolut(FolderType.PaymentLogo, tempName), SettingsPictureSize.PaymentIconWidth, SettingsPictureSize.PaymentIconHeight, image); } imgIcon.ImageUrl = FoldersHelper.GetPath(FolderType.PaymentLogo, tempName, true); imgIcon.Visible = true; } } }
public ActionResult AddPhoto(Photo photo) { return Json(_photoService.AddPhoto(photo),JsonRequestBehavior.AllowGet); }
private void ProcessExcel() { try { // How much ? ------------------ int intRootCategories = 7; int intSubCategoriesLevel1 = 7; int intSubCategoriesLevel2 = 7; int intProductCountForCategory = 150; // Internal Variables ------------------ int intCurrentProductIndex = SQLDataHelper.GetInt(SQLDataAccess.ExecuteScalar("Select MAX(ProductId) + 1 FROM Catalog.Product", CommandType.Text, null)); // 50000 int intProductAltId1 = 0; int intProductAltId2 = 0; int intProductAltId3 = 0; int intProductAltId4 = 0; int intProductAltId5 = 0; int intProductAltId6 = 0; string strCategoryName1 = ""; string strCategoryName2 = ""; string strCategoryName3 = ""; string strPropName1 = ""; string strPropName2 = ""; string strPropName3 = ""; string strPropName4 = ""; string strPropName5 = ""; string strPropName6 = ""; string strPropName7 = ""; int intTempProductId = 0; //int i, j, k; var rnd = new Random(); // --------------- ImportStatistic.TotalRow = (intRootCategories * intSubCategoriesLevel1 * intSubCategoriesLevel2 * intProductCountForCategory); // Step by rows for (int i = 0; i <= intRootCategories - 1; i++) // 15 { strCategoryName1 = Strings.GetRandomString(rnd, 25, 6); if (!chbSimpleMode.Checked) // Simple Mode { strPropName1 = Strings.GetRandomString(rnd, 4); strPropName2 = Strings.GetRandomString(rnd, 7); strPropName3 = Strings.GetRandomString(rnd, 7); strPropName4 = Strings.GetRandomString(rnd, 8); strPropName5 = Strings.GetRandomString(rnd, 8); strPropName6 = Strings.GetRandomString(rnd, 9); strPropName7 = Strings.GetRandomString(rnd, 9); } for (int j = 0; j <= intSubCategoriesLevel1 - 1; j++) // 15 x 10 { strCategoryName2 = Strings.GetRandomString(rnd, 25, 5); for (int k = 0; k <= intSubCategoriesLevel2 - 1; k++) // 15 x 10 x 10 { strCategoryName3 = Strings.GetRandomString(rnd, 25, 4); for (int p = 0; p <= intProductCountForCategory - 1; p++) // 15 x 10 x 10 x 10 { intCurrentProductIndex++; intTempProductId = ProcessProduct(rnd, intCurrentProductIndex); // Category ---------------------------------------------------------------------------------------------- string parentCategory = string.Format("[{0} >> {1} >> {2}]", strCategoryName1.Trim(), strCategoryName2.Trim(), strCategoryName3.Trim()); CategoryService.SubParseAndCreateCategory(parentCategory, intTempProductId); if (!chbSimpleMode.Checked) // Simple Mode { // Property ----------------------------------------------------------------------------------------------- BuildProperties(rnd, intTempProductId, strPropName1, strPropName2, strPropName3, strPropName4, strPropName5, strPropName6, strPropName7); // Images ------------------------------------------------------------------------------------------------- var tempId = PhotoService.AddPhoto(new Photo(0, intTempProductId, PhotoType.Product) { Description = Strings.GetRandomString(rnd, 25, 4) }); if (!string.IsNullOrWhiteSpace(tempId)) { CopyProductPic(rnd, tempId); } tempId = PhotoService.AddPhoto(new Photo(0, intTempProductId, PhotoType.Product) { Description = Strings.GetRandomString(rnd, 25, 4) }); if (!string.IsNullOrWhiteSpace(tempId)) { CopyProductPic(rnd, tempId); } tempId = PhotoService.AddPhoto(new Photo(0, intTempProductId, PhotoType.Product) { Description = Strings.GetRandomString(rnd, 25, 4) }); if (!string.IsNullOrWhiteSpace(tempId)) { CopyProductPic(rnd, tempId); } // Alt Products -------------------------------------------------------------------------------------------- if (intProductAltId1 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId1, RelatedType.Alternative); } if (intProductAltId2 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId2, RelatedType.Alternative); } if (intProductAltId3 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId3, RelatedType.Alternative); } if (intProductAltId4 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId4, RelatedType.Alternative); } if (intProductAltId5 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId5, RelatedType.Alternative); } if (intProductAltId6 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId6, RelatedType.Alternative); } // And RelatedProduct --------------------------------------------- if (intProductAltId1 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId1, RelatedType.Related); } if (intProductAltId2 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId2, RelatedType.Related); } if (intProductAltId3 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId3, RelatedType.Related); } // And RelatedProduct if (intProductAltId4 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId4, RelatedType.Related); } if (intProductAltId5 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId5, RelatedType.Related); } if (intProductAltId6 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId6, RelatedType.Related); } //intProductAltId1 = intProductAltId2; //intProductAltId2 = intProductAltId3; //intProductAltId3 = intTempProductId; intProductAltId1 = intProductAltId2; intProductAltId2 = intProductAltId3; intProductAltId3 = intProductAltId4; intProductAltId4 = intProductAltId5; intProductAltId5 = intProductAltId6; intProductAltId6 = intTempProductId; // Custom Options -------------------------------------------------------------------------------------------- var copt = new CustomOption(true) { CustomOptionsId = -1, ProductId = intTempProductId }; // copt.InputType = CustomOptionInputType.RadioButton; copt.Title = Demo.GetRandomCity(); var opt = new OptionItem { OptionId = -1, PriceBc = 0, SortOrder = 10 }; opt.Title = Demo.GetRandomName(); var opt2 = new OptionItem { OptionId = -1, PriceBc = DevTool.GetRandomInt(rnd, 0, 100), SortOrder = 20 }; opt2.Title = Demo.GetRandomLastName(); var opt3 = new OptionItem { OptionId = -1, PriceBc = DevTool.GetRandomInt(rnd, 0, 10), SortOrder = 30 }; opt3.Title = Demo.GetRandomName(); copt.Options = new List <OptionItem> { opt, opt2, opt3 }; CustomOptionsService.AddCustomOption(copt); } } } } } CategoryService.RecalculateProductsCountManual(); //TODO find where is this function! //ProductService.SumImportLog(Resource.Admin_ImportXLS_UpdoadingSuccessfullyCompleted,Resource.Admin_ImportXLS_UpdoadingCompletedWithErrors); } catch (Exception ex) { MsgErr(ex.Message + " at xls"); Debug.LogError(ex); } ImportStatistic.IsRun = false; ImportStatistic.ThreadImport.Abort(); }
private void SaveMenuItem() { if (_mode == eMenuMode.Err) { return; } if (!ValidateData()) { return; } var url = string.Empty; if (txtUrl.Text.Contains("www.")) { url = txtUrl.Text.Contains("http://") || txtUrl.Text.Contains("https://") ? txtUrl.Text : "http://" + txtUrl.Text; } else { url = txtUrl.Text; } lblError.Text = String.Empty; var mItem = new AdvMenuItem { MenuItemID = _menuItemId, MenuItemName = txtName.Text, MenuItemParentID = string.IsNullOrEmpty(hParent.Value) ? 0 : Convert.ToInt32(hParent.Value), MenuItemUrlPath = url, SortOrder = Convert.ToInt32(txtSortOrder.Text), Blank = ckbBlank.Checked, Enabled = ckbEnabled.Checked, MenuItemUrlType = (EMenuItemUrlType)Convert.ToInt32(rblLinkType.SelectedValue), ShowMode = (EMenuItemShowMode)Convert.ToInt32(ddlShowMode.SelectedValue), NoFollow = ckbNofollow.Checked }; if (IconFileUpload.HasFile) { PhotoService.DeletePhotos(_menuItemId, PhotoType.MenuIcon); using (IconFileUpload.FileContent) { var tempName = PhotoService.AddPhoto(new Photo(0, _menuItemId, PhotoType.MenuIcon) { OriginName = IconFileUpload.FileName }); if (!string.IsNullOrWhiteSpace(tempName)) { IconFileUpload.SaveAs(FoldersHelper.GetPathAbsolut(FolderType.MenuIcons, tempName)); } mItem.MenuItemIcon = tempName; } } else { mItem.MenuItemIcon = pnlIcon.Visible ? imgIcon.ToolTip : null; } MenuService.UpdateMenuItem(mItem, _type); if (_type == MenuService.EMenuType.Top) { CacheManager.RemoveByPattern(CacheNames.GetMainMenuCacheObjectName()); CacheManager.RemoveByPattern(CacheNames.GetMainMenuAuthCacheObjectName()); } else if (_type == MenuService.EMenuType.Bottom) { var cacheName = CacheNames.GetBottomMenuCacheObjectName(); if (CacheManager.Contains(cacheName)) { CacheManager.Remove(cacheName); } var cacheAuthName = CacheNames.GetBottomMenuAuthCacheObjectName(); if (CacheManager.Contains(cacheAuthName)) { CacheManager.Remove(cacheAuthName); } } }
/// <summary> /// Загружает фото из одной папки в другую и обновляет данные в базе /// </summary> /// <returns>количество загруженных файлов, -1 если загрузка не удалась</returns> /// <remarks></remarks> private int UploadImages() { string sourceFolder = (Server.MapPath(txtSource.Text)); int upCounter = 0; if (!Directory.Exists(sourceFolder)) { msgErr(Resources.Resource.Admin_UploadImages_SourceFolderNotFound); return(-1); } var di = new DirectoryInfo(sourceFolder); FileInfo[] files = di.GetFiles("*.jpg"); foreach (FileInfo fi in files) { var productId = PhotoService.CheckImageInDataBase(fi.Name); if (productId == 0) // -1 { try { if (fi.Name.StartsWith("no_product_") == false) { fi.CopyTo(fi.DirectoryName + "\\no_product_" + fi.Name); fi.Delete(); } } catch (Exception ex) { Debug.LogError(ex); msgErr(string.Format(Resources.Resource.Admin_UploadImages_ProductNotFound, fi.Name), eStates.err); } } else { try { var tempName = PhotoService.AddPhoto(new Photo(0, productId, PhotoType.Product) { OriginName = fi.Name }); if (!string.IsNullOrWhiteSpace(tempName)) { using (Image image = Image.FromFile(sourceFolder + "\\" + fi.Name)) { FileHelpers.SaveProductImageUseCompress(tempName, image); } msgErr(string.Format(Resources.Resource.Admin_UploadImages_4Photo, fi.Name)); upCounter += 1; } } catch (Exception ex) { Debug.LogError(ex); msgErr(string.Format(Resources.Resource.Admin_UploadImages_AddImageError, fi.Name), eStates.err); } } } msgErr(string.Format(Resources.Resource.Admin_UploadImages_UploadFinal, upCounter)); return(upCounter); }
private int CreateCategory() { // Validation MsgErr(true); if (string.IsNullOrEmpty(txtName.Text)) { MsgErr(Resource.Admin_m_Category_NoName); return(0); } if (string.IsNullOrEmpty(txtSynonym.Text)) { MsgErr(Resource.Admin_m_Category_NoSynonym); return(0); } var reg = new Regex("^[a-zA-Z0-9_-]*$"); if (!reg.IsMatch(txtSynonym.Text)) { MsgErr(Resource.Admin_m_Category_SynonymInfo); return(0); } if (!UrlService.IsAvailableUrl(ParamType.Category, txtSynonym.Text)) { MsgErr(Resource.Admin_SynonymExist); return(0); } if ((PictureFileUpload.HasFile && !FileHelpers.CheckFileExtension(PictureFileUpload.FileName, FileHelpers.eAdvantShopFileTypes.Image)) || (MiniPictureFileUpload.HasFile && !FileHelpers.CheckFileExtension(MiniPictureFileUpload.FileName, FileHelpers.eAdvantShopFileTypes.Image))) { MsgErr(Resource.Admin_ErrorMessage_WrongImageExtension); return(0); } var myCat = new Category { Name = txtName.Text, ParentCategoryId = tree.SelectedValue.TryParseInt(), Description = fckDescription.Text, BriefDescription = fckBriefDescription.Text, SortOrder = txtSortIndex.Text.TryParseInt(), Enabled = ChkEnableCategory.Checked, DisplayChildProducts = false, //ChkDisplayChildProducts.Checked, DisplayStyle = SubCategoryDisplayStyle.SelectedValue, UrlPath = txtSynonym.Text, Meta = new MetaInfo(0, 0, MetaType.Category, txtTitle.Text, txtMetaKeywords.Text, txtMetaDescription.Text, txtH1.Text), Sorting = (ESortOrder)ddlSorting.SelectedValue.TryParseInt() }; try { myCat.CategoryId = CategoryService.AddCategory(myCat, true); if (myCat.CategoryId == 0) { return(0); } if (PictureFileUpload.HasFile) { var tempName = PhotoService.AddPhoto(new Photo(0, myCat.CategoryId, PhotoType.CategoryBig) { OriginName = PictureFileUpload.FileName }); if (!string.IsNullOrWhiteSpace(tempName)) { using (Image image = Image.FromStream(PictureFileUpload.FileContent)) FileHelpers.SaveResizePhotoFile(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Big, tempName), SettingsPictureSize.BigCategoryImageWidth, SettingsPictureSize.BigCategoryImageHeight, image); } } if (MiniPictureFileUpload.HasFile) { var tempName = PhotoService.AddPhoto(new Photo(0, myCat.CategoryId, PhotoType.CategorySmall) { OriginName = MiniPictureFileUpload.FileName }); if (!string.IsNullOrWhiteSpace(tempName)) { using (Image image = Image.FromStream(MiniPictureFileUpload.FileContent)) FileHelpers.SaveResizePhotoFile(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Small, tempName), SettingsPictureSize.SmallCategoryImageWidth, SettingsPictureSize.SmallCategoryImageHeight, image); } } TrialService.TrackEvent(TrialEvents.AddCategory, ""); return(myCat.CategoryId); } catch (Exception ex) { MsgErr(ex.Message + "at CreateCategory"); Debug.LogError(ex, false); } return(0); }
protected void SaveCategory() { if (_mode == eCategoryMode.Err) { return; } int categoryID = _categoryId; lblError.Text = string.Empty; string synonym = txtSynonym.Text.Trim(); if (String.IsNullOrEmpty(synonym)) { MsgErr(Resource.Admin_m_Category_NoSynonym); return; } string oldSynonym = UrlService.GetObjUrlFromDb(ParamType.Category, categoryID); if (oldSynonym != synonym) { var reg = new Regex("^[a-zA-Z0-9_-]*$"); if (!reg.IsMatch(synonym)) { MsgErr(Resource.Admin_m_Category_SynonymInfo); return; } if (!UrlService.IsAvailableUrl(categoryID, ParamType.Category, synonym)) { MsgErr(Resource.Admin_SynonymExist); return; } } var c = new Category { CategoryId = categoryID, Name = txtName.Text, ParentCategoryId = tree.SelectedValue.TryParseInt(), Description = fckDescription.Text == "<br />" || fckDescription.Text == " " || fckDescription.Text == "\r\n" ? string.Empty : fckDescription.Text, BriefDescription = fckBriefDescription.Text == "<br />" || fckBriefDescription.Text == " " || fckBriefDescription.Text == "\r\n" ? string.Empty : fckBriefDescription.Text, Enabled = ChkEnableCategory.Checked, DisplayStyle = SubCategoryDisplayStyle.SelectedValue, DisplayChildProducts = false, //ChkDisplayChildProducts.Checked, DisplayBrandsInMenu = ChkDisplayBrands.Checked, DisplaySubCategoriesInMenu = ChkDisplaySubCategories.Checked, UrlPath = synonym, SortOrder = txtSortIndex.Text.TryParseInt(), Sorting = (ESortOrder)ddlSorting.SelectedValue.TryParseInt() }; FileHelpers.UpdateDirectories(); if (PictureFileUpload.HasFile) { if (!FileHelpers.CheckFileExtension(PictureFileUpload.FileName, FileHelpers.eAdvantShopFileTypes.Image)) { MsgErr(Resource.Admin_ErrorMessage_WrongImageExtension); return; } PhotoService.DeletePhotos(_categoryId, PhotoType.CategoryBig); var tempName = PhotoService.AddPhoto(new Photo(0, categoryID, PhotoType.CategoryBig) { OriginName = PictureFileUpload.FileName }); if (!string.IsNullOrWhiteSpace(tempName)) { using (Image image = Image.FromStream(PictureFileUpload.FileContent)) FileHelpers.SaveResizePhotoFile(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Big, tempName), SettingsPictureSize.BigCategoryImageWidth, SettingsPictureSize.BigCategoryImageHeight, image); } } if (MiniPictureFileUpload.HasFile) { if (!FileHelpers.CheckFileExtension(MiniPictureFileUpload.FileName, FileHelpers.eAdvantShopFileTypes.Image)) { MsgErr(Resource.Admin_ErrorMessage_WrongImageExtension); return; } PhotoService.DeletePhotos(_categoryId, PhotoType.CategorySmall); var tempName = PhotoService.AddPhoto(new Photo(0, categoryID, PhotoType.CategorySmall) { OriginName = MiniPictureFileUpload.FileName }); if (!string.IsNullOrWhiteSpace(tempName)) { using (Image image = Image.FromStream(MiniPictureFileUpload.FileContent)) FileHelpers.SaveResizePhotoFile(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Small, tempName), SettingsPictureSize.SmallCategoryImageWidth, SettingsPictureSize.SmallCategoryImageHeight, image); } } if (IconFileUpload.HasFile) { if (!FileHelpers.CheckFileExtension(IconFileUpload.FileName, FileHelpers.eAdvantShopFileTypes.Image)) { MsgErr(Resource.Admin_ErrorMessage_WrongImageExtension); return; } PhotoService.DeletePhotos(_categoryId, PhotoType.CategoryIcon); var tempName = PhotoService.AddPhoto(new Photo(0, categoryID, PhotoType.CategoryIcon) { OriginName = IconFileUpload.FileName }); if (!string.IsNullOrWhiteSpace(tempName)) { using (Image image = Image.FromStream(IconFileUpload.FileContent)) FileHelpers.SaveResizePhotoFile(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Icon, tempName), SettingsPictureSize.IconCategoryImageWidth, SettingsPictureSize.IconCategoryImageHeight, image); } } c.Meta = new MetaInfo(0, c.CategoryId, MetaType.Category, txtTitle.Text, txtMetaKeywords.Text, txtMetaDescription.Text, txtH1.Text); var isParentCategoryChanged = CategoryService.GetCategory(_categoryId).ParentCategoryId != c.ParentCategoryId; if (!CategoryService.UpdateCategory(c, true)) { MsgErr("Failed to save category"); } if (isParentCategoryChanged) { CategoryService.RecalculateProductsCountManual(); CategoryService.ClearCategoryCache(); } }