示例#1
0
        public IActionResult Create(ArticleVM artvm)
        {
            if (ModelState.IsValid)
            {
                //Obteniendo la ruta principal del proyecto (wwwroot)
                string mainPath = hostEnvironment.WebRootPath;
                //Obteniendo la solicitud de la subida de los archivos...
                var files = HttpContext.Request.Form.Files;
                if (artvm.vm_Article.ArticleID == 0)
                {
                    //Nuevo Articulo
                    //Creación de un hash para los nombre de las imagenes de modo que sean unicas
                    string fileName = Guid.NewGuid().ToString();
                    //Estableciendo la ruta donde se guardarán las imagenes
                    var uploads   = Path.Combine(mainPath, @"images\articles");
                    var extension = Path.GetExtension(files[0].FileName);
                    using (var fileStreams = new FileStream(Path.Combine(uploads, fileName + extension), FileMode.Create))
                    {
                        files[0].CopyTo(fileStreams);
                    }

                    artvm.vm_Article.ArticleImageUrl     = @"\images\articles\" + fileName + extension;
                    artvm.vm_Article.ArticleCreationDate = DateTime.Now.ToString();

                    iworkUnit.Article.Add(artvm.vm_Article);
                    iworkUnit.Save();

                    return(RedirectToAction(nameof(Index)));
                }
            }

            artvm.vm_ListCategories = iworkUnit.Category.GetListCategories();
            return(View(artvm));
        }
示例#2
0
        public IActionResult Create(SliderModel slider)
        {
            if (ModelState.IsValid)
            {
                string mainPath = hostEnvironment.WebRootPath;
                var    files    = HttpContext.Request.Form.Files;

                //Nuevo Slider
                string fileName  = Guid.NewGuid().ToString();
                var    uploads   = Path.Combine(mainPath, @"images\sliders");
                var    extension = Path.GetExtension(files[0].FileName);

                using (var fileStreams = new FileStream(Path.Combine(uploads, fileName + extension), FileMode.Create))
                {
                    files[0].CopyTo(fileStreams);
                }

                slider.SliderImageUrl = @"\images\sliders\" + fileName + extension;
                iworkUnit.Slider.Add(slider);
                iworkUnit.Save();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(slider));
        }
示例#3
0
        public IActionResult Create(CategoryModel category)
        {
            if (ModelState.IsValid)
            {
                iworkUnit.Category.Add(category);
                iworkUnit.Save();
                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
 public IActionResult Upsert(Category category)
 {
     if (ModelState.IsValid)
     {
         if (category.Id == 0)
         {
             _workUnit.Category.Add(category);
         }
         else
         {
             _workUnit.Category.Update(category);
         }
         _workUnit.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(category));
 }
示例#5
0
 public IActionResult Upsert(Brand brand)
 {
     if (ModelState.IsValid)
     {
         if (brand.Id == 0)
         {
             _workUnit.Brand.Add(brand);
         }
         else
         {
             _workUnit.Brand.Update(brand);
         }
         _workUnit.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(brand));
 }
示例#6
0
 public IActionResult Upsert(Warehouse warehouse)
 {
     if (ModelState.IsValid)
     {
         if (warehouse.Id == 0)
         {
             _workUnit.Warehouse.Add(warehouse);
         }
         else
         {
             _workUnit.Warehouse.Update(warehouse);
         }
         _workUnit.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(warehouse));
 }
示例#7
0
        public ContactsViewModel(IWorkUnitProvider workUnitProvider)
        {
            WorkUnitProvider = workUnitProvider;

            LoadAllContacts = new SimplerCommand
            {
                Action = () =>
                {
                    WorkUnit       = WorkUnitProvider.ProvideWorkUnit();
                    LoadedContacts = new ObservableCollection <Contact>(WorkUnit.Contacts.GetAll());
                    NotifyChangesMade();
                }
            };
            SaveAllContacts = new SimpleCommand
            {
                Action = () => {
                    WorkUnit.Save();
                    LoadedContacts.ToList().ForEach(c => WorkUnit.Reload(c));
                    NotifyChangesMade();
                },
                CanExecuteFunc = () => WorkUnit?.IsChanged() ?? false
            };
            OnEditEnding = new SimplerCommand
            {
                Action = SaveAllContacts.RaiseCanExecuteChanged
            };
            DeleteSelected = new SimpleCommand
            {
                Action = () =>
                {
                    SelectedContacts.ToList().ForEach(c => LoadedContacts.Remove(c));
                },
                CanExecuteFunc = () => {
                    return(SelectedContacts?.Count > 0);
                }
            };
            OnSelectionChange = new SimplerCommand <IList>
            {
                Action = o =>
                {
                    SelectedContacts = new ObservableCollection <Contact>(o.OfType <Contact>());
                }
            };
        }
        public IActionResult Upsert(ProductViewModel productViewModel)
        {
            if (ModelState.IsValid)
            {
                //Load Images
                string webRootPath = _hostEnviroment.WebRootPath;
                var    files       = HttpContext.Request.Form.Files;//Get files from form

                if (files.Count > 0)
                {
                    string filename  = Guid.NewGuid().ToString();
                    var    uploads   = Path.Combine(webRootPath, @"images\products");
                    var    extension = Path.GetExtension(files[0].FileName);

                    if (productViewModel.Product.ImageUrl != null)
                    {
                        //To edit, we need remove the olderone
                        var imagePath = Path.Combine(webRootPath, productViewModel.Product.ImageUrl.TrimStart('\\'));
                        if (System.IO.File.Exists(imagePath))
                        {
                            System.IO.File.Delete(imagePath);
                        }
                    }

                    using (var filesStreams = new FileStream(Path.Combine(uploads, filename + extension), FileMode.Create))
                    {
                        files[0].CopyTo(filesStreams);
                    }
                    productViewModel.Product.ImageUrl = @"\images\products\" + filename + extension;
                }
                else
                {
                    //Update and the user doesnt change the image
                    if (productViewModel.Product.Id != 0)
                    {
                        Product productDb = _workUnit.Product.Get(productViewModel.Product.Id);
                        productViewModel.Product.ImageUrl = productDb.ImageUrl;
                    }
                }


                if (productViewModel.Product.Id == 0)
                {
                    _workUnit.Product.Add(productViewModel.Product);
                }
                else
                {
                    _workUnit.Product.Update(productViewModel.Product);
                }

                _workUnit.Save();
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                productViewModel.CategoryList = _workUnit.Category.GetAll().Select(c => new SelectListItem
                {
                    Text  = c.Name,
                    Value = c.Id.ToString(),
                });
                productViewModel.BrandList = _workUnit.Brand.GetAll().Select(b => new SelectListItem
                {
                    Text  = b.Name,
                    Value = b.Id.ToString(),
                });
                productViewModel.FatherList = _workUnit.Product.GetAll().Select(p => new SelectListItem
                {
                    Text  = p.Description,
                    Value = p.Id.ToString(),
                });

                if (productViewModel.Product.Id != 0)
                {
                    productViewModel.Product = _workUnit.Product.Get(productViewModel.Product.Id);
                }
            }

            return(View(productViewModel.Product));
        }