public void AddTextWatermarkThrowsOnIncorrectHexColorLength()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            Assert.Throws <ArgumentException>(
                () => image.AddTextWatermark("p9", fontColor: "#F000"),
                "The \"fontColor\" value is invalid. Valid values are names like \"White\", \"Black\", or \"DarkBlue\", or hexadecimal values in the form \"#RRGGBB\" or \"#RGB\".");
        }
Exemplo n.º 2
0
        public void AddTextWatermarkThrowsOnIncorrectFontFamily()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            Assert.Throws <ArgumentException>(
                () => image.AddTextWatermark("p9", fontFamily: "something"),
                "The \"fontFamily\" value is invalid. Valid values are font family names like: \"Arial\", \"Times New Roman\", etc. Make sure that the font family you are trying to use is installed on the server.");
        }
        public void AddTextWatermarkThrowsOnEmptyText()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            Assert.ThrowsArgumentNullOrEmptyString(
                () => image.AddTextWatermark(""),
                "text");
        }
Exemplo n.º 4
0
        public void AddTextWatermarkThrowsOnIncorrectFontStyle()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            Assert.Throws <ArgumentException>(
                () => image.AddTextWatermark("p9", fontStyle: "something"),
                "The \"fontStyle\" value is invalid. Valid values are: \"Regular\", \"Bold\", \"Italic\", \"Underline\", and \"Strikeout\".");
        }
Exemplo n.º 5
0
        public void AddTextWatermarkThrowsOnIncorrectVerticalAlignment()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            Assert.Throws <ArgumentException>(
                () => image.AddTextWatermark("p9", verticalAlign: "NotSet"),
                "The \"verticalAlign\" value is invalid. Valid values are: \"Top\", \"Bottom\", and \"Middle\".");
        }
Exemplo n.º 6
0
        public void ResimBoyutlandir(int en, int boy, string yol)
        {
            WebImage img = new WebImage(yol);

            img.Resize(en, boy, false);
            img.AddTextWatermark("W11.com", fontColor: "Tomato", fontSize: 18, fontFamily: "Verdana");
            img.Save(yol);
        }
        public void AddTextWatermarkThrowsOnIncorrectHorizontalAlignment()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            Assert.Throws <ArgumentException>(
                () => image.AddTextWatermark("p9", horizontalAlign: "Justify"),
                "The \"horizontalAlign\" value is invalid. Valid values are: \"Right\", \"Left\", and \"Center\".");
        }
Exemplo n.º 8
0
        public void AddTextWatermarkDoesNotChangeImageIfPaddingIsTooBig()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            image.AddTextWatermark("Plan9", padding: 1000);

            Assert.Equal(634, image.Width);
            Assert.Equal(489, image.Height);
        }
        public async Task <JsonResult> UploadAvatar()
        {
            if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any())
            {
                string dosyayolu = string.Empty;
                try
                {
                    var    foto     = System.Web.HttpContext.Current.Request.Files["myAvatar"];
                    string fileName = Path.GetFileNameWithoutExtension(foto.FileName);
                    string extName  = Path.GetExtension(foto.FileName);
                    fileName += Guid.NewGuid().ToString().Replace("-", "");
                    fileName  = SiteSettings.UrlFormatConverter(fileName);
                    dosyayolu = Server.MapPath("../Upload/Avatars/") + fileName + extName;
                    foto.SaveAs(dosyayolu);

                    WebImage img = new WebImage(dosyayolu);
                    img.Resize(200, 200, false);
                    img.AddTextWatermark("Wissen", "RoyalBlue", opacity: 95, fontSize: 25, fontFamily: "Verdana");
                    img.Save(dosyayolu);


                    var userStore   = MembershipTools.NewUserStore();
                    var userManager = new UserManager <ApplicationUser>(userStore);
                    var user        = userManager.FindById(HttpContext.User.Identity.GetUserId());

                    if (!string.IsNullOrEmpty(user.AvatarPath))
                    {
                        var silinecekResim = Server.MapPath(user.AvatarPath);
                        System.IO.File.Delete(silinecekResim);
                    }

                    user.AvatarPath = "../Upload/Avatars/" + fileName + extName;
                    await userStore.UpdateAsync(user);

                    await userStore.Context.SaveChangesAsync();

                    return(Json(new
                    {
                        success = true,
                        path = user.AvatarPath
                    }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new
                    {
                        success = false,
                        errmessage = ex.Message
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(new
            {
                success = false,
                errmessage = "Hata Oluştu"
            }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 10
0
        public void AddTextWatermarkPreservesImageDimension()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            image.AddTextWatermark("Plan9", fontSize: 16, horizontalAlign: "Left", verticalAlign: "Bottom", opacity: 50);

            Assert.Equal(634, image.Width);
            Assert.Equal(489, image.Height);
        }
Exemplo n.º 11
0
        public void AddTextWatermarkParsesShortHexColorCorrectly()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            image.AddTextWatermark("Plan9", fontSize: 16, fontColor: "#F00", horizontalAlign: "Center", verticalAlign: "Middle");

            Assert.Equal(634, image.Width);
            Assert.Equal(489, image.Height);
        }
Exemplo n.º 12
0
        public void AddTextWatermarkThrowsOnNegativePadding()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            Assert.ThrowsArgumentGreaterThanOrEqualTo(
                () => image.AddTextWatermark("p9", padding: -10),
                "padding",
                "0");
        }
Exemplo n.º 13
0
        public void AddTextWatermarkThrowsOnTooBigOpacity()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            Assert.ThrowsArgumentOutOfRange(
                () => image.AddTextWatermark("Plan9", opacity: 155),
                "opacity",
                "Value must be between 0 and 100."
                );
        }
Exemplo n.º 14
0
        public void Process(string p)
        {
            WebImage image = new WebImage(this.ImagePath);

            switch (p)
            {
            case "Original":
                break;

            case "RotateLeft":
                image.RotateLeft();
                break;

            case "RotateRight":
                image.RotateRight();
                break;

            case "FlipHorizontal":
                image.FlipHorizontal();
                break;

            case "FlipVertical":
                image.FlipVertical();
                break;

            case "Resize":
                image.Resize(image.Width / 2, image.Height / 2, preserveAspectRatio: true);
                break;

            case "AddTextWatermark":
                image.AddTextWatermark("Elif Furuncu", fontColor: "Red", fontSize: 14, horizontalAlign: "Center", verticalAlign: "Bottom");
                break;

            case "AddImageWatermark":
                WebImage watermark = new WebImage(this.ImagePath);
                watermark.Resize(50, 50);
                watermark = watermark.Save(Server.MapPath("~/images/watermark.jpeg"), imageFormat: "jpeg");
                image.AddImageWatermark(watermark.FileName, 50, 50, verticalAlign: "Top", horizontalAlign: "Right", opacity: 75);
                break;

            case "Crop":
                image.Crop(0, 0, 100, 100);
                break;

            default:
                break;
            }

            string savePath = Server.MapPath("~/images/last.jpeg");

            WebImage savedImage = image.Save(savePath, imageFormat: "jpeg");


            image.Write();
        }
Exemplo n.º 15
0
        public void CanAddTextAndImageWatermarks()
        {
            WebImage watermark = new WebImage(_BmpImageBytes);
            WebImage image     = new WebImage(_JpgImageBytes);

            image.AddImageWatermark(watermark, horizontalAlign: "LEFT", verticalAlign: "top", opacity: 30, padding: 10);
            image.AddTextWatermark("plan9");

            Assert.Equal(634, image.Width);
            Assert.Equal(489, image.Height);
        }
Exemplo n.º 16
0
 public ActionResult ResimDuzenle(HttpPostedFileBase[] resimDeneme2)
 {
     if (Session["ud"] is Urunler)
     {
         string FileName = "";
         HttpFileCollectionBase files     = Request.Files;
         List <Resimler>        rslistesi = new List <Resimler>();
         int sayac = 0;
         foreach (HttpPostedFileBase item in resimDeneme2)
         {
             int i = sayac++;
             HttpPostedFileBase file = files[i];
             string             fname;
             fname    = file.FileName;
             FileName = file.FileName;
             FileInfo fileinfo = new FileInfo(file.FileName);
             WebImage img      = new WebImage(file.InputStream);
             string   uzanti   = (Guid.NewGuid().ToString() + fileinfo.Extension).ToLower();
             img.Resize(1200, 900, true, false);
             if (img.Height < 1200 || img.Width < 900)
             {
                 img.AddTextWatermark("www.teklifiNedir.com", "#fff825", 15, "Regular", "Arial", "Center", "middle", 100, 50);
             }
             else
             {
                 img.AddTextWatermark("www.teklifiNedir.com", "#fff825", 50, "Regular", "Arial", "Center", "middle", 100, 50);
             }
             string tamyol = "/Temp/" + uzanti;
             img.Save(Server.MapPath(tamyol));
             rslistesi.Add(
                 new Resimler()
             {
                 ImageUrl = tamyol,
                 Resim    = uzanti
             });
         }
         Session["resduz"] = rslistesi;
         return(RedirectToAction("AnaResimDuz", "Post"));
     }
     return(View());
 }
Exemplo n.º 17
0
        public static bool UploadImage(HttpPostedFileBase file, string folder, ref string savedFile, int width, int height, string WatermarkText = "")
        {
            //Check file name
            if (file == null || file.FileName.Length < 1)
            {
                return(false);
            }

            string _file = Path.Combine(ValueConstant.IMAGE_PATH + folder);
            string _path = HttpContext.Current.Server.MapPath(_file);

            //Create folder
            if (!Directory.Exists(_path))
            {
                Directory.CreateDirectory(_path);
            }

            _file = Path.Combine(_file, Path.GetFileName(file.FileName));
            _path = Path.Combine(_path, Path.GetFileName(file.FileName));

            if (!File.Exists(_path))
            {
                try
                {
                    WebImage image = new WebImage(file.InputStream);
                    if (width > 0)
                    {
                        if (height == 0)
                        {
                            height = width;
                        }
                        image.Resize(width, height);
                    }
                    if (WatermarkText.Length > 0)
                    {
                        image.AddTextWatermark(WatermarkText);
                    }
                    image.Save(_path);

                    savedFile = _file;
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }
            else
            {
                savedFile = _file;
            }

            return(true);
        }
Exemplo n.º 18
0
        public async Task <ActionResult> Edit(Product model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Güncelleme işleminde bir hata oluştu");
                return(View(model));
            }

            try
            {
                var urun = await new ProductRepo().GetByIdAsync(model.ProductID);
                if (urun == null)
                {
                    ModelState.AddModelError("", "Ürün bulunamadı");
                    return(View(model));
                }

                urun.ProductName = model.ProductName;
                urun.UnitPrice   = model.UnitPrice;
                if (model.Foto != null && model.Foto.ContentLength > 0)
                {
                    var    dosya    = model.Foto;
                    string fileName = Path.GetFileNameWithoutExtension(dosya.FileName);
                    string extName  = Path.GetExtension(dosya.FileName);
                    fileName  = SiteSettings.UrlFormatConverter(fileName);
                    fileName += Guid.NewGuid().ToString().Replace("-", "");
                    var directoryPath = Server.MapPath("~/Uploads/Products");
                    var filePath      = Server.MapPath($"~/Uploads/Products/{fileName}{extName}");
                    if (!Directory.Exists(directoryPath))
                    {
                        Directory.CreateDirectory(directoryPath);
                    }
                    dosya.SaveAs(filePath);
                    WebImage img = new WebImage(filePath);
                    img.Resize(800, 800, false);
                    img.AddTextWatermark("Kuzey Ticaret", fontColor: "Tomato", fontSize: 18, fontFamily: "Verdana");
                    img.Save(filePath);
                    if (!string.IsNullOrEmpty(urun.FotoUrl))
                    {
                        System.IO.File.Delete(Server.MapPath(urun.FotoUrl));
                    }
                    urun.FotoUrl = $@"/Uploads/Products/{fileName}{extName}";
                }
                await new ProductRepo().UpdateAsync();
                return(RedirectToAction("Edit", "Product", new { id = model.ProductID }));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(model));
            }
        }
Exemplo n.º 19
0
        public async Task <ActionResult> Profile(ProfilePasswordMultiViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                var userStore   = MembershipTools.NewUserStore();
                var userManager = new UserManager <ApplicationUser>(userStore);
                var user        = await userManager.FindByIdAsync(HttpContext.User.Identity.GetUserId());

                user.Name    = model.ProfileViewModel.Name;
                user.Surname = model.ProfileViewModel.Surname;
                user.Bio     = model.ProfileViewModel.Bio;
                user.Email   = model.ProfileViewModel.Email;
                if (model.ProfileViewModel.Photo != null && model.ProfileViewModel.Photo.ContentLength > 0)
                {
                    string fileName      = Path.GetFileNameWithoutExtension(model.ProfileViewModel.Photo.FileName);
                    string extensionName = Path.GetExtension(model.ProfileViewModel.Photo.FileName);
                    fileName  = SiteSettings.UrlFormatConverter(fileName);
                    fileName += Guid.NewGuid().ToString().Replace("-", "");
                    var directoryPath = Server.MapPath("~/Uploads/ProfilePhotos/");
                    var filePath      = Server.MapPath("~/Uploads/ProfilePhotos/" + fileName + extensionName);
                    if (!Directory.Exists(directoryPath))
                    {
                        Directory.CreateDirectory(directoryPath);
                    }
                    model.ProfileViewModel.Photo.SaveAs(filePath);
                    WebImage img = new WebImage(filePath);
                    img.Resize(800, 800, false);
                    img.AddTextWatermark("Murat Bircan Blog", fontColor: "antiquewhite", fontSize: 18, fontFamily: "Verdana");
                    img.Save(filePath);
                    if (!string.IsNullOrEmpty(user.PhotoURL) && user.PhotoURL != "/images/user.png")
                    {
                        System.IO.File.Delete(Server.MapPath(user.PhotoURL));
                    }
                    user.PhotoURL = $@"/Uploads/ProfilePhotos/{fileName}{extensionName}";
                }
                await userStore.UpdateAsync(user);

                await userStore.Context.SaveChangesAsync();

                return(RedirectToAction("Profile", "Account"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", $"Güncelleme sırasında bir hata oluştu.{ex.Message}");
                return(View("Profile"));
            }
        }
Exemplo n.º 20
0
 private int addTextWatermark(string ImagePath)
 {
     try
     {
         WebImage objWaqtermarkImage = new WebImage(ImagePath);
         objWaqtermarkImage.AddTextWatermark("© Mugurtham", "White", 60, "Regular", "Consolas", "Right", "Bottom", 70, 5);
         objWaqtermarkImage.Save(ImagePath);
     }
     catch (Exception objEx)
     {
         Helpers.LogExceptionInFlatFile(objEx);
     }
     return(0);
 }
Exemplo n.º 21
0
        public ActionResult Add(MalfunctionViewModel model)
        {
            try
            {
                var data = new Malfunction()
                {
                    Message   = model.Message,
                    Type      = model.Type,
                    BrandType = model.BrandType
                };

                if (model.PostedFile != null &&
                    model.PostedFile.ContentLength > 0)
                {
                    var    file     = model.PostedFile;
                    string fileName = Path.GetFileNameWithoutExtension(file.FileName);
                    string extName  = Path.GetExtension(file.FileName);
                    fileName  = StringHelpers.UrlFormatConverter(fileName);
                    fileName += StringHelpers.GetCode();
                    var klasoryolu = Server.MapPath("~/Upload/");
                    var dosyayolu  = Server.MapPath("~/Upload/") + fileName + extName;

                    if (!Directory.Exists(klasoryolu))
                    {
                        Directory.CreateDirectory(klasoryolu);
                    }
                    file.SaveAs(dosyayolu);

                    WebImage img = new WebImage(dosyayolu);
                    img.Resize(250, 250, false);
                    img.AddTextWatermark("Wissen");
                    img.Save(dosyayolu);
                    data.AvatarPath = "/Upload/" + fileName + extName;
                }



                var a = new MalfunctionRepo().Insert(data);

                TempData["Message"] = $"Kaydınız Alınmıştır";
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 22
0
 public static byte[] AddWaterMark(string filePath, string text)
 {
     using (var img = System.Drawing.Image.FromFile(filePath))
     {
         using (var memStream = new MemoryStream())
         {
             using (var bitmap = new Bitmap(img)) // to avoid GDI+ errors
             {
                 bitmap.Save(memStream, ImageFormat.Png);
                 var content  = memStream.ToArray();
                 var webImage = new WebImage(memStream);
                 webImage.AddTextWatermark(text, verticalAlign: "Top", horizontalAlign: "Left", fontColor: "Brown");
                 return(webImage.GetBytes());
             }
         }
     }
 }
Exemplo n.º 23
0
        public static void ResimBoyutlandir(string resimad, int buyukGenislik, int kucukGenislik)
        {
            var    resimBuyukYol       = Path.Combine(HttpContext.Current.Server.MapPath("~/Userimage/"), resimad);
            var    resim               = new WebImage(resimBuyukYol);
            string filenameNoExtension = Path.GetFileNameWithoutExtension(resimBuyukYol);
            string extension           = Path.GetExtension(resimBuyukYol);
            string filename            = Path.GetFileName(resimBuyukYol);

            if (resim.Width > buyukGenislik)
            {
                resim.Resize(buyukGenislik, ((buyukGenislik * resim.Height) / resim.Width), preserveAspectRatio: true);
                //resim.Resize(kucukGenislik, ((kucukGenislik * resim.Width) / resim.Height), preserveAspectRatio: true);
            }
            //var resimKucukYol = Path.Combine(HttpContext.Current.Server.MapPath("~/Upload/slide-show/"), buyukGenislik + "-px-" + filenameNoExtension + extension);
            resim.AddTextWatermark("Torbalı Burada", "White", 40, "Regular", "Arial", "Center", "Middle", 20, 5);
            resim.Save(resimBuyukYol);

            //return buyukGenislik + "-px-" + filenameNoExtension + extension;
        }
Exemplo n.º 24
0
 public void AddTextWatermarkThrowsOnIncorrectHexColorLength()
 {
     WebImage image = new WebImage(_JpgImageBytes);
     Assert.Throws<ArgumentException>(
         () => image.AddTextWatermark("p9", fontColor: "#F000"),
         "The \"fontColor\" value is invalid. Valid values are names like \"White\", \"Black\", or \"DarkBlue\", or hexadecimal values in the form \"#RRGGBB\" or \"#RGB\".");
 }
Exemplo n.º 25
0
        public async Task <ActionResult> Add(ProductViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.ProductList  = GetProductSelectList();
                ViewBag.CategoryList = GetCategorySelectList();
                return(View(model));
            }

            try
            {
                if (model.Product.SupProductId.ToString().Replace("0", "").Replace("-", "").Length == 0)
                {
                    model.Product.SupProductId = null;
                }

                model.Product.LastPriceUpdateDate = DateTime.Now;
                Product product = new Product()
                {
                    Category            = model.Product.Category,
                    Description         = model.Product.Description,
                    ProductName         = model.Product.ProductName,
                    SalesPrice          = model.Product.SalesPrice,
                    BuyPrice            = model.Product.BuyPrice,
                    Id                  = model.Product.Id,
                    ImagePath           = model.Product.ImagePath,
                    Barcode             = model.Product.Barcode,
                    CreatedDate         = model.Product.CreatedDate,
                    Invoices            = model.Product.Invoices,
                    LastPriceUpdateDate = model.Product.LastPriceUpdateDate,
                    ProductType         = model.Product.ProductType,
                    Products            = model.Product.Products,
                    Quantity            = model.Product.Quantity,
                    SupProduct          = model.Product.SupProduct,
                    SupProductId        = model.Product.SupProductId,
                    UnitsInStock        = model.Product.UnitsInStock,
                    UpdatedDate         = model.Product.UpdatedDate
                };
                product.CategoryId = model.Product.CategoryId;
                if (model.PostedFile != null &&
                    model.PostedFile.ContentLength > 0)
                {
                    MemoryStream target = new MemoryStream();
                    model.PostedFile.InputStream.CopyTo(target);
                    byte[] data = target.ToArray();
                    model.Image = data;


                    var    file     = model.PostedFile;
                    string fileName = Path.GetFileNameWithoutExtension(file.FileName);
                    string extName  = Path.GetExtension(file.FileName);
                    fileName  = StringHelpers.UrlFormatConverter(fileName);
                    fileName += StringHelpers.GetCode();
                    var klasoryolu = Server.MapPath("~/Upload/");
                    var dosyayolu  = Server.MapPath("~/Upload/") + fileName + extName;

                    if (!Directory.Exists(klasoryolu))
                    {
                        Directory.CreateDirectory(klasoryolu);
                    }
                    file.SaveAs(dosyayolu);

                    WebImage img = new WebImage(dosyayolu);
                    img.Resize(250, 250, false);
                    img.AddTextWatermark("Wissen");
                    img.Save(dosyayolu);
                    product.ImagePath = "/Upload/" + fileName + extName;
                }
                await new ProductRepo().InsertAsync(product);
                TempData["Message"] = $"{model.Product.ProductName} isimli ürün başarıyla eklenmiştir";
                return(RedirectToAction("Add"));
            }
            catch (DbEntityValidationException ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {EntityHelpers.ValidationMessage(ex)}",
                    ActionName     = "Add",
                    ControllerName = "Product",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
            catch (Exception ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "Add",
                    ControllerName = "Product",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 26
0
        public ActionResult Add(CategoryViewModel model)
        {
            try
            {
                if (model.SupCategoryId == 0)
                {
                    model.SupCategoryId = null;
                }
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError("CategoryName", "100 karakteri geçme kardeş");
                    model.SupCategoryId  = model.SupCategoryId ?? 0;
                    ViewBag.CategoryList = GetCategorySelectList();
                    return(View(model));
                }

                if (model.SupCategoryId > 0)
                {
                    model.TaxRate = new CategoryRepo().GetById(model.SupCategoryId).TaxRate;
                }
                if (model.PostedFile != null &&
                    model.PostedFile.ContentLength > 0)
                {
                    var    file     = model.PostedFile;
                    string fileName = Path.GetFileNameWithoutExtension(file.FileName);
                    string extName  = Path.GetExtension(file.FileName);
                    fileName  = StringHelpers.UrlFormatConverter(fileName);
                    fileName += StringHelpers.GetCode();
                    var klasoryolu = Server.MapPath("~/Product/");
                    var dosyayolu  = Server.MapPath("~/Product/") + fileName + extName;

                    if (!Directory.Exists(klasoryolu))
                    {
                        Directory.CreateDirectory(klasoryolu);
                    }
                    file.SaveAs(dosyayolu);

                    WebImage img = new WebImage(dosyayolu);
                    img.Resize(250, 250, false);
                    img.AddTextWatermark("Wissen");
                    img.Save(dosyayolu);
                    //var oldPath = user.AvatarPath;
                    model.CategoryPath = "/Product/" + fileName + extName;
                }

                var model2 = new Category
                {
                    CategoryName  = model.CategoryName,
                    CategoryPath  = model.CategoryPath,
                    SupCategoryId = model.SupCategoryId,
                    TaxRate       = model.TaxRate,
                };
                new CategoryRepo().Insert(model2);
                TempData["Message"] = $"{model.CategoryName} isimli kategori başarıyla eklenmiştir";
                return(RedirectToAction("Add"));
            }
            catch (DbEntityValidationException ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {EntityHelpers.ValidationMessage(ex)}",
                    ActionName     = "Add",
                    ControllerName = "Category",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
            catch (Exception ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "Add",
                    ControllerName = "Category",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 27
0
        public ActionResult Update(CategoryViewModel model)
        {
            try
            {
                if (model.SupCategoryId == 0)
                {
                    model.SupCategoryId = null;
                }
                if (!ModelState.IsValid)
                {
                    model.SupCategoryId  = model.SupCategoryId ?? 0;
                    ViewBag.CategoryList = GetCategorySelectList();
                    return(View(model));
                }

                if (model.SupCategoryId > 0)
                {
                    model.TaxRate = new CategoryRepo().GetById(model.SupCategoryId).TaxRate;
                }

                var data = new CategoryRepo().GetById(model.Id);
                data.CategoryName  = model.CategoryName;
                data.TaxRate       = model.TaxRate;
                data.SupCategoryId = model.SupCategoryId;
                if (model.PostedFile != null &&
                    model.PostedFile.ContentLength > 0)
                {
                    var    file     = model.PostedFile;
                    string fileName = Path.GetFileNameWithoutExtension(file.FileName);
                    string extName  = Path.GetExtension(file.FileName);
                    fileName  = StringHelpers.UrlFormatConverter(fileName);
                    fileName += StringHelpers.GetCode();
                    var klasoryolu = Server.MapPath("~/Product/");
                    var dosyayolu  = Server.MapPath("~/Product/") + fileName + extName;

                    if (!Directory.Exists(klasoryolu))
                    {
                        Directory.CreateDirectory(klasoryolu);
                    }
                    file.SaveAs(dosyayolu);

                    WebImage img = new WebImage(dosyayolu);
                    img.Resize(250, 250, false);
                    img.AddTextWatermark("Wissen");
                    img.Save(dosyayolu);
                    model.CategoryPath = "/Product/" + fileName + extName;
                }

                data.CategoryPath = model.CategoryPath;

                new CategoryRepo().Update(data);
                foreach (var dataCategory in data.Categories)
                {
                    dataCategory.TaxRate = data.TaxRate;
                    new CategoryRepo().Update(dataCategory);
                    if (dataCategory.Categories.Any())
                    {
                        UpdateSubTaxRate(dataCategory.Categories);
                    }
                }

                void UpdateSubTaxRate(ICollection <Category> dataC)
                {
                    foreach (var dataCategory in dataC)
                    {
                        dataCategory.TaxRate = data.TaxRate;
                        new CategoryRepo().Update(dataCategory);
                        if (dataCategory.Categories.Any())
                        {
                            UpdateSubTaxRate(dataCategory.Categories);
                        }
                    }
                }
                TempData["Message"]  = $"{model.CategoryName} isimli kategori başarıyla güncellenmiştir";
                ViewBag.CategoryList = GetCategorySelectList();
                return(View(model));
            }
            catch (DbEntityValidationException ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {EntityHelpers.ValidationMessage(ex)}",
                    ActionName     = "Add",
                    ControllerName = "Category",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
            catch (Exception ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "Add",
                    ControllerName = "Category",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 28
0
        public void AddTextWatermarkThrowsOnIncorrectFontSize()
        {
            WebImage image = new WebImage(_JpgImageBytes);
            Assert.ThrowsArgumentGreaterThan(
                () => image.AddTextWatermark("p9", fontSize: -10),
                "fontSize",
                "0");

            Assert.ThrowsArgumentGreaterThan(
                () => image.AddTextWatermark("p9", fontSize: 0),
                "fontSize",
                "0");
        }
Exemplo n.º 29
0
        public void AddTextWatermarkDoesNotChangeImageIfPaddingIsTooBig()
        {
            WebImage image = new WebImage(_JpgImageBytes);
            image.AddTextWatermark("Plan9", padding: 1000);

            Assert.Equal(634, image.Width);
            Assert.Equal(489, image.Height);
        }
Exemplo n.º 30
0
        public ActionResult Ekle(ArizaViewModel model)
        {
            try
            {
                var id   = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId();
                var user = NewUserManager().FindById(id);
                // arıza fotoğrafı
                if (model.UrunFotografi != null &&
                    model.UrunFotografi.ContentLength > 0)
                {
                    var    file     = model.UrunFotografi;
                    string fileName = Path.GetFileNameWithoutExtension(file.FileName);
                    string extName  = Path.GetExtension(file.FileName);
                    fileName  = StringHelpers.UrlFormatConverter(fileName);
                    fileName += StringHelpers.GetCode();
                    var klasoryolu = Server.MapPath("~/ArizaFoto/");
                    var dosyayolu  = Server.MapPath("~/ArizaFoto/") + fileName + extName;

                    if (!Directory.Exists(klasoryolu))
                    {
                        Directory.CreateDirectory(klasoryolu);
                    }
                    file.SaveAs(dosyayolu);

                    WebImage img = new WebImage(dosyayolu);
                    img.Resize(250, 250, false);
                    img.AddTextWatermark("FK");
                    img.Save(dosyayolu);
                    var oldPath = model.UrunResmi;
                    model.UrunResmi = "/ArizaFoto/" + fileName + extName;

                    System.IO.File.Delete(Server.MapPath(oldPath));
                }

                // arıza fotoğrafı
                if (model.UrunFaturaFotografi != null &&
                    model.UrunFaturaFotografi.ContentLength > 0)
                {
                    var    file     = model.UrunFaturaFotografi;
                    string fileName = Path.GetFileNameWithoutExtension(file.FileName);
                    string extName  = Path.GetExtension(file.FileName);
                    fileName  = StringHelpers.UrlFormatConverter(fileName);
                    fileName += StringHelpers.GetCode();
                    var klasoryolu = Server.MapPath("~/FaturaFoto/");
                    var dosyayolu  = Server.MapPath("~/FaturaFoto/") + fileName + extName;

                    if (!Directory.Exists(klasoryolu))
                    {
                        Directory.CreateDirectory(klasoryolu);
                    }
                    file.SaveAs(dosyayolu);

                    WebImage img = new WebImage(dosyayolu);
                    img.Resize(250, 250, false);
                    img.AddTextWatermark("FK");
                    img.Save(dosyayolu);
                    var oldPath = model.FaturaResmi;
                    model.FaturaResmi = "/FaturaFoto/" + fileName + extName;

                    System.IO.File.Delete(Server.MapPath(oldPath));
                }

                new ArizaRepo().Insert(new Ariza()
                {
                    UrunTipi      = model.UrunTipi,
                    UrunAdi       = model.UrunAdi,
                    MusteriYorumu = model.MusteriYorumu,
                    UrunResmi     = model.UrunResmi,
                    FaturaResmi   = model.FaturaResmi,
                    SehirAdi      = model.SehirAdi,
                    Adres         = model.Adres,
                    GarantiDurumu = model.GarantiDurumu,
                    MusteriId     = id
                });
            }
            catch (Exception)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Arıza Eklenmesi Sırasında Bir Hata Oluştu",
                    ActionName     = "ArizaKayit",
                    ControllerName = "Musteri",
                    ErrorCode      = 404
                };
                return(RedirectToAction("Error", "Home"));
            }
            return(RedirectToAction("ArizaKayit", "Musteri"));
        }
Exemplo n.º 31
0
 public void AddTextWatermarkThrowsOnIncorrectVerticalAlignment()
 {
     WebImage image = new WebImage(_JpgImageBytes);
     Assert.Throws<ArgumentException>(
         () => image.AddTextWatermark("p9", verticalAlign: "NotSet"),
         "The \"verticalAlign\" value is invalid. Valid values are: \"Top\", \"Bottom\", and \"Middle\".");
 }
Exemplo n.º 32
0
        public void AddTextWatermarkParsesShortHexColorCorrectly()
        {
            WebImage image = new WebImage(_JpgImageBytes);
            image.AddTextWatermark("Plan9", fontSize: 16, fontColor: "#F00", horizontalAlign: "Center", verticalAlign: "Middle");

            Assert.Equal(634, image.Width);
            Assert.Equal(489, image.Height);
        }
Exemplo n.º 33
0
 public void AddTextWatermarkThrowsOnNegativePadding()
 {
     WebImage image = new WebImage(_JpgImageBytes);
     Assert.ThrowsArgumentGreaterThanOrEqualTo(
         () => image.AddTextWatermark("p9", padding: -10),
         "padding",
         "0");
 }
Exemplo n.º 34
0
 public void AddTextWatermarkThrowsOnEmptyText()
 {
     WebImage image = new WebImage(_JpgImageBytes);
     Assert.ThrowsArgumentNullOrEmptyString(
         () => image.AddTextWatermark(""),
         "text");
 }
Exemplo n.º 35
0
        public async Task <ActionResult> UpdateProfile(ProfilePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("UserProfile", model));
            }

            try
            {
                var userManager = NewUserManager();
                var user        = await userManager.FindByIdAsync(model.UserProfileViewModel.Id);

                user.Name        = model.UserProfileViewModel.Name;
                user.Surname     = model.UserProfileViewModel.Surname;
                user.PhoneNumber = model.UserProfileViewModel.PhoneNumber;
                if (User.IsInRole("Technician"))
                {
                    user.TechnicianStatus = model.UserProfileViewModel.TechnicianStatus;
                    user.Latitude         = model.UserProfileViewModel.Latitude;
                    user.Longitude        = model.UserProfileViewModel.Longitude;
                }

                if (user.Email != model.UserProfileViewModel.Email)
                {
                    //todo tekrar aktivasyon maili gönderilmeli. rolü de aktif olmamış role çevrilmeli.
                }
                user.Email = model.UserProfileViewModel.Email;

                if (model.UserProfileViewModel.PostedFile != null &&
                    model.UserProfileViewModel.PostedFile.ContentLength > 0)
                {
                    var    file     = model.UserProfileViewModel.PostedFile;
                    string fileName = Path.GetFileNameWithoutExtension(file.FileName);
                    string extName  = Path.GetExtension(file.FileName);
                    fileName  = StringHelpers.UrlFormatConverter(fileName);
                    fileName += StringHelpers.GetCode();
                    var klasoryolu = Server.MapPath("~/Upload/");
                    var dosyayolu  = Server.MapPath("~/Upload/") + fileName + extName;

                    if (!Directory.Exists(klasoryolu))
                    {
                        Directory.CreateDirectory(klasoryolu);
                    }
                    file.SaveAs(dosyayolu);

                    WebImage img = new WebImage(dosyayolu);
                    img.Resize(250, 250, false);
                    img.AddTextWatermark("Teknik Servisçi");
                    img.Save(dosyayolu);
                    var oldPath = user.AvatarPath;
                    user.AvatarPath = "/Upload/" + fileName + extName;

                    System.IO.File.Delete(Server.MapPath(oldPath));
                }


                await userManager.UpdateAsync(user);

                TempData["Message"] = "Güncelleme işlemi başarılı";
                return(RedirectToAction("UserProfile"));
            }
            catch (Exception ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "UserProfile",
                    ControllerName = "Account",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 36
0
        public void AddTextWatermarkThrowsOnTooBigOpacity()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            Assert.ThrowsArgumentOutOfRange(() => image.AddTextWatermark("Plan9", opacity: 155), "opacity", "Value must be between 0 and 100.");
        }
Exemplo n.º 37
0
 public void AddTextWatermarkThrowsOnIncorrectHorizontalAlignment()
 {
     WebImage image = new WebImage(_JpgImageBytes);
     Assert.Throws<ArgumentException>(
         () => image.AddTextWatermark("p9", horizontalAlign: "Justify"),
         "The \"horizontalAlign\" value is invalid. Valid values are: \"Right\", \"Left\", and \"Center\".");
 }
Exemplo n.º 38
0
 public static void WaterMark(
     [BlobTrigger(@"images2-output/{name}")] WebImage input,
     [Blob(@"images2-newoutput/{name}")] out WebImage output)
 {
     output = input.AddTextWatermark("WebJobs is now awesome!!!!", fontSize: 6);
 }
Exemplo n.º 39
0
        public void AddTextWatermarkThrowsOnIncorrectFontStyle()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            Assert.Throws<ArgumentException>(
                () => image.AddTextWatermark("p9", fontStyle: "something"),
                "The \"fontStyle\" value is invalid. Valid values are: \"Regular\", \"Bold\", \"Italic\", \"Underline\", and \"Strikeout\".");
        }
Exemplo n.º 40
0
        public void AddTextWatermarkThrowsOnIncorrectFontFamily()
        {
            WebImage image = new WebImage(_JpgImageBytes);

            Assert.Throws<ArgumentException>(
                () => image.AddTextWatermark("p9", fontFamily: "something"),
                "The \"fontFamily\" value is invalid. Valid values are font family names like: \"Arial\", \"Times New Roman\", etc. Make sure that the font family you are trying to use is installed on the server.");
        }
Exemplo n.º 41
0
        public void AddTextWatermarkPreservesImageDimension()
        {
            WebImage image = new WebImage(_JpgImageBytes);
            image.AddTextWatermark("Plan9", fontSize: 16, horizontalAlign: "Left", verticalAlign: "Bottom", opacity: 50);

            Assert.Equal(634, image.Width);
            Assert.Equal(489, image.Height);
        }
        public async Task <ActionResult> EditUser(UserProfileViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                var userManager = NewUserManager();
                var user        = await userManager.FindByIdAsync(model.Id);

                user.Ad          = model.Ad;
                user.Soyad       = model.Soyad;
                user.PhoneNumber = model.TelefonNO;
                user.Email       = model.Email;
                user.Adres       = model.Adres;
                user.SehirAdi    = model.SehirAdi;

                if (model.PostedFile != null &&
                    model.PostedFile.ContentLength > 0)
                {
                    var    file     = model.PostedFile;
                    string fileName = Path.GetFileNameWithoutExtension(file.FileName);
                    string extName  = Path.GetExtension(file.FileName);
                    fileName  = StringHelpers.UrlFormatConverter(fileName);
                    fileName += StringHelpers.GetCode();
                    var klasoryolu = Server.MapPath("~/Upload/");
                    var dosyayolu  = Server.MapPath("~/Upload/") + fileName + extName;

                    if (!Directory.Exists(klasoryolu))
                    {
                        Directory.CreateDirectory(klasoryolu);
                    }
                    file.SaveAs(dosyayolu);

                    WebImage img = new WebImage(dosyayolu);
                    img.Resize(250, 250, false);
                    img.AddTextWatermark("Wissen");
                    img.Save(dosyayolu);
                    var oldPath = user.AvatarPath;
                    user.AvatarPath = "/Upload/" + fileName + extName;

                    System.IO.File.Delete(Server.MapPath(oldPath));
                }
                await userManager.UpdateAsync(user);

                TempData["Message"] = "Güncelleme işlemi başarılı";
                return(RedirectToAction("EditUser", new { id = user.Id }));
            }
            catch (Exception ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "Index",
                    ControllerName = "Admin",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home", new { area = "" }));
            }
        }
Exemplo n.º 43
0
        public void CanAddTextAndImageWatermarks()
        {
            WebImage watermark = new WebImage(_BmpImageBytes);
            WebImage image = new WebImage(_JpgImageBytes);
            image.AddImageWatermark(watermark, horizontalAlign: "LEFT", verticalAlign: "top", opacity: 30, padding: 10);
            image.AddTextWatermark("plan9");

            Assert.Equal(634, image.Width);
            Assert.Equal(489, image.Height);
        }