public IActionResult Index(BrandVM brandVM)
 {
     try
     {
         Brand brand = new Brand()
         {
             Name        = brandVM.Name,
             Code        = brandVM.Code,
             Description = brandVM.Description,
         };
         if (brandVM.Logo != null)
         {
             var           fileName = ContentDispositionHeaderValue.Parse(brandVM.Logo.ContentDisposition).FileName.Trim('"').Replace(" ", string.Empty);
             List <string> separate = fileName.Split(".").ToList();
             fileName = separate[0] + DateTime.Now.ToString("dddd_dd_MMMM_yyyy_HH_mm_ss") + "." + separate[1];
             string path = image.GetImagePath(fileName, "Brand");
             using (var stream = new FileStream(path, FileMode.Create))
             {
                 brandVM.Logo.CopyTo(stream);
             }
             brand.LogoUrl = image.GetImagePathForDb(path);
         }
         context.Brand.Add(brand);
         context.Save();
         return(Json(true));
     }
     catch (Exception ex)
     {
         return(Json(ex.Message));
     }
 }
예제 #2
0
        public IActionResult Index(ProductVM productVM)
        {
            try
            {
                #region Product
                Product product = new Product()
                {
                    Name            = productVM.Name,
                    Description     = productVM.Description,
                    CategoryId      = productVM.CategoryId,
                    BrandId         = productVM.BrandId,
                    UnitId          = productVM.UnitId,
                    WarningQuantity = productVM.WarningQuantity,
                };
                if (productVM.Photo != null)
                {
                    var           fileName = ContentDispositionHeaderValue.Parse(productVM.Photo.ContentDisposition).FileName.Trim('"').Replace(" ", string.Empty);
                    List <string> separate = fileName.Split(".").ToList();
                    fileName = separate[0] + DateTime.Now.ToString("dddd_dd_MMMM_yyyy_HH_mm_ss") + "." + separate[1];
                    string path = image.GetImagePath(fileName, "Product");
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        productVM.Photo.CopyTo(stream);
                    }
                    product.PhotoUrl = image.GetImagePathForDb(path);
                }
                context.Product.Add(product);
                context.Save();
                #endregion


                #region Inventory
                Inventory inventory = new Inventory()
                {
                    ProductId         = product.Id,
                    AvailableQuantity = 0,
                };
                context.Inventory.Add(inventory);
                context.Save();
                #endregion

                return(Json(true));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));

                throw;
            }
        }
        private string UploadImage(string prefix, IFormFile photo, string folderName)
        {
            string fileName    = image.GetUniqueImageName(prefix, photo);
            string imagePath   = image.GetImagePath(fileName, folderName);
            string dbImagePath = image.GetImagePathForDb(imagePath);

            using (var stream = new FileStream(imagePath, FileMode.Create))
            {
                photo.CopyTo(stream);
            }
            return(dbImagePath);
        }
        public IActionResult Supplier(SupplierVM supplierVM)
        {
            try
            {
                Supplier supplier = new Supplier()
                {
                    Name        = supplierVM.Name,
                    Email       = supplierVM.Email,
                    NID         = supplierVM.NID,
                    Address     = supplierVM.Address,
                    Phone       = supplierVM.Phone,
                    CompanyName = supplierVM.CompanyName,
                    Designation = supplierVM.Designation,
                };

                if (supplierVM.Photo != null)
                {
                    var           fileName = ContentDispositionHeaderValue.Parse(supplierVM.Photo.ContentDisposition).FileName.Trim('"').Replace(" ", string.Empty);
                    List <string> separate = fileName.Split(".").ToList();
                    fileName = separate[0] + DateTime.Now.ToString("dddd_dd_MMMM_yyyy_HH_mm_ss") + "." + separate[1];
                    string path = image.GetImagePath(fileName, "Supplier");
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        supplierVM.Photo.CopyTo(stream);
                    }
                    supplier.PhotoUrl = image.GetImagePathForDb(path);
                }
                context.Supplier.Add(supplier);
                context.Save();
                return(Json(true));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
        }