Example #1
0
        public IActionResult Edit(IFormFile image, ChooseUs choseUs)
        {
            var chouseUsImage = _work.ChooseUs.Get(choseUs.Id);

            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    var fileName = ContentDispositionHeaderValue.Parse(image.ContentDisposition).FileName.Trim('"').Replace(" ", string.Empty);
                    var path     = _imagePath.GetImagePath(fileName, "ChouseUs", chouseUsImage.Id.ToString());
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        image.CopyTo(stream);
                    }
                    chouseUsImage.Image = _imagePath.GetImagePathForDb(path);
                }
                chouseUsImage.Id               = choseUs.Id;
                chouseUsImage.Title            = choseUs.Title;
                chouseUsImage.ShortDescription = choseUs.ShortDescription;
                chouseUsImage.Order            = choseUs.Order;
                chouseUsImage.IsActive         = choseUs.IsActive;
                _work.ChooseUs.Update(chouseUsImage);
                _work.Complete();

                return(PartialView("_Edit", chouseUsImage));
            }
            return(PartialView("_Edit", chouseUsImage));
        }
Example #2
0
        public IActionResult Index()
        {
            HomeViewModel homeViewModel = new HomeViewModel();

            homeViewModel.BannerList = _work.Banner.GetAll();

            var chooseUsList = _work.ChooseUs.GetAll();

            foreach (var item in chooseUsList)
            {
                ChooseUs chooseUs = new ChooseUs
                {
                    Id               = item.Id,
                    Title            = item.Title,
                    Description      = item.Description,
                    Order            = item.Order,
                    ShortDescription = Regex.Replace(item.ShortDescription, "<[^>]*>", "")
                };
                homeViewModel.ChooseUsList.Add(chooseUs);
            }

            homeViewModel.ClientList = _work.Client.GetAll();

            homeViewModel.ProductList = _work.Products.GetAllWithCategory();

            homeViewModel.HostingPlans = _work.HostingPlan.GetAll();

            return(View(homeViewModel));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("ID,Option,Image")] ChooseUs chooseUs, IFormFile Img)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToAction(nameof(AccountController.Login), "Account"));
            }

            if (ModelState.IsValid)
            {
                if (Img != null)
                {
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", Img.FileName);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await Img.CopyToAsync(stream);
                    }
                    chooseUs.Image = Img.FileName;
                }
                else
                {
                    var path = "default.png";
                    chooseUs.Image = path;
                }
                chooseUs = _empleadosData.AddReason(chooseUs);
                return(RedirectToAction(nameof(Index)));
            }
            return(View(chooseUs));
        }
Example #4
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Option,Image")] ChooseUs chooseUs, IFormFile Img)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToAction(nameof(AccountController.Login), "Account"));
            }
            if (id != chooseUs.ID)
            {
                return(NotFound());
            }

            if (Img == null)
            {
                if (chooseUs != null)
                {
                    _context.Update(chooseUs);
                    _context.SaveChanges();
                    return(RedirectToAction(nameof(Index)));
                }
            }
            else
            {
                var image = Img.FileName;

                try
                {
                    if (image != null)
                    {
                        var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", Img.FileName);

                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await Img.CopyToAsync(stream);
                        }
                        chooseUs.Image = Img.FileName;

                        _context.Update(chooseUs);
                        await _context.SaveChangesAsync();
                    }
                }

                catch (DbUpdateConcurrencyException)
                {
                    if (!ChooseUsExists(chooseUs.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(chooseUs));
        }
Example #5
0
 public IActionResult Edit(ChooseUs choseUs)
 {
     if (ModelState.IsValid)
     {
         _work.ChooseUs.Update(choseUs);
         _work.Complete();
     }
     return(PartialView("_Edit", choseUs));
 }
Example #6
0
 public IActionResult Create(ChooseUs choseUs)
 {
     if (ModelState.IsValid)
     {
         _work.ChooseUs.Add(choseUs);
         _work.Complete();
         ModelState.Clear();
         choseUs = new ChooseUs();
         return(PartialView("_Create", choseUs));
     }
     return(PartialView("_Create", choseUs));
 }
Example #7
0
        public async Task <IActionResult> Create([Bind("ID,Option,Image")] ChooseUs chooseUs, IFormFile Img)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToAction(nameof(AccountController.Login), "Account"));
            }

            if (ModelState.IsValid)
            {
                if (Img != null)
                {
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", Img.FileName);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await Img.CopyToAsync(stream);
                    }
                    chooseUs.Image = Img.FileName;
                }
                else
                {
                    var path = "default.png";
                    chooseUs.Image = path;
                }
                var notification = new Notifications();

                TempData["sms"]      = "Campo aƱadido correctamente";
                ViewBag.sms          = TempData["sms"];
                notification.Detalle = ViewBag.sms;
                notification.Section = "Razones para elegirnos";
                notification.Tipo    = "check";
                notification.Time    = DateTime.Now;
                notification         = _empleadosData.AddNotification(notification);

                chooseUs = _empleadosData.AddReason(chooseUs);
                return(RedirectToAction(nameof(Index)));
            }
            return(View(chooseUs));
        }
Example #8
0
 public IActionResult Create(IFormFile image, ChooseUs choseUs)
 {
     if (ModelState.IsValid)
     {
         if (image != null)
         {
             var fileName = ContentDispositionHeaderValue.Parse(image.ContentDisposition).FileName.Trim('"').Replace(" ", string.Empty);
             var path     = _imagePath.GetImagePath(fileName, "ChoseUs", choseUs.Id.ToString());
             using (var stream = new FileStream(path, FileMode.Create))
             {
                 image.CopyTo(stream);
             }
             choseUs.Image = _imagePath.GetImagePathForDb(path);
         }
         _work.ChooseUs.Add(choseUs);
         _work.Complete();
         ModelState.Clear();
         choseUs = new ChooseUs();
         return(PartialView("_Create", choseUs));
     }
     return(PartialView("_Create", choseUs));
 }
Example #9
0
        public IActionResult CreateView()
        {
            ChooseUs chose = new ChooseUs();

            return(PartialView("_Create", chose));
        }
Example #10
0
 public ChooseUs AddReason(ChooseUs chooseUs)
 {
     _context.ChooseUs.Add(chooseUs);
     _context.SaveChanges();
     return(chooseUs);
 }
Example #11
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Option,Image")] ChooseUs chooseUs, IFormFile Img)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToAction(nameof(AccountController.Login), "Account"));
            }
            if (id != chooseUs.ID)
            {
                return(NotFound());
            }

            if (Img == null)
            {
                if (chooseUs != null)
                {
                    var notification = new Notifications();
                    TempData["sms"]      = "Se han guardado los cambios correctamente";
                    ViewBag.sms          = TempData["sms"];
                    notification.Detalle = ViewBag.sms;
                    notification.Section = "Motivos para elegirnos";
                    notification.Tipo    = "check";
                    notification.Time    = DateTime.Now;
                    notification         = _empleadosData.AddNotification(notification);
                    _context.Update(chooseUs);
                    _context.SaveChanges();
                    return(RedirectToAction(nameof(Index)));
                }
            }
            else
            {
                var image = Img.FileName;

                try
                {
                    if (image != null)
                    {
                        var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", Img.FileName);

                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await Img.CopyToAsync(stream);
                        }
                        var notification = new Notifications();
                        chooseUs.Image       = Img.FileName;
                        TempData["sms"]      = "Se han guardado los cambios correctamente";
                        ViewBag.sms          = TempData["sms"];
                        notification.Detalle = ViewBag.sms;
                        notification.Section = "Motivos para elegirnos";
                        notification.Tipo    = "check";
                        notification.Time    = DateTime.Now;
                        notification         = _empleadosData.AddNotification(notification);

                        _context.Update(chooseUs);
                        await _context.SaveChangesAsync();
                    }
                }

                catch (DbUpdateConcurrencyException)
                {
                    if (!ChooseUsExists(chooseUs.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(chooseUs));
        }