Пример #1
0
        // GET: Products/Create
        //[Authorize(Roles = "User")]
        public ActionResult Create()
        {
            var user = db.Users
                       .Where(u => u.UserName == User.Identity.Name)
                       .FirstOrDefault();

            if (user == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            ViewBag.CategoryId = new SelectList(
                CombosHelper.GetCategories(user.CompanyId),
                "CategoryId", "Description");

            ViewBag.TaxId = new SelectList(
                CombosHelper.GetTaxes(user.CompanyId),
                "TaxId", "Description");

            var product = new Product
            {
                CompanyId = user.CompanyId
            };

            return(View(product));
        }
        public ActionResult Create(Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                var folder   = "~/Content/Products";
                var file     = string.Format("{0}.jpg", product.ProductId);
                var response = FilesHelper.UploadPhoto(product.ImageFile, folder, file);
                if (response)
                {
                    var pic = string.Format("{0}/{1}", folder, file);
                    product.Image           = pic;
                    db.Entry(product).State = EntityState.Modified;
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(user.CompanyId), "CategoryId", "Description",
                                                product.CategoryId);
            ViewBag.TaxId = new SelectList(CombosHelper.GetTaxxes(user.CompanyId), "TaxId", "Description", product.TaxId);
            return(View(product));
        }
        public ActionResult Edit(Product product)
        {
            if (ModelState.IsValid)
            {
                if (product.ImageFile != null)
                {
                    var pic      = string.Empty;
                    var folder   = "~/Content/Products";
                    var file     = string.Format("{0}.jpg", product.ProductId);
                    var response = FilesHelper.UploadPhoto(product.ImageFile, folder, file);
                    if (response)
                    {
                        pic           = string.Format("{0}/{1}", folder, file);
                        product.Image = pic;
                    }
                }

                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(product.CompanyId), "CategoryId",
                                                "Description");
            ViewBag.TaxId = new SelectList(CombosHelper.GetTaxxes(product.CompanyId), "TaxId", "Description");
            return(View(product));
        }
Пример #4
0
        // GET: Products/Edit/5
        //[Authorize(Roles = "User")]
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Product product = db.Products.Find(id);

            if (product == null)
            {
                return(HttpNotFound());
            }

            ViewBag.CategoryId = new SelectList(
                CombosHelper.GetCategories(product.CompanyId),
                "CategoryId", "Description",
                product.CategoryId);

            ViewBag.TaxId = new SelectList(
                CombosHelper.GetTaxes(product.CompanyId),
                "TaxId", "Description",
                product.TaxId);

            return(View(product));
        }
Пример #5
0
        public async Task <ActionResult> Edit(ProductView view)
        {
            if (ModelState.IsValid)
            {
                var pic    = view.Image;
                var folder = "~/Content/Products";

                if (view.ImageFile != null)
                {
                    pic = FilesHelper.UploadPhoto(view.ImageFile, folder);
                    pic = string.Format("{0}/{1}", folder, pic);
                }

                var product = ToProduct(view);
                product.Image           = pic;
                db.Entry(product).State = EntityState.Modified;
                var response = await DBHelper.SaveChangesAsync(db);

                if (response.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(string.Empty, response.Message);
            }

            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(), "CategoryId", "Description", view.CategoryId);
            return(View(view));
        }
 public ActionResult Create()
 {
     ViewBag.CategoryId     = new SelectList(CombosHelper.GetCategories(), "CategoryId", "Description");
     ViewBag.ColonyId       = new SelectList(CombosHelper.GetColonies(0), "ColonyId", "Description");
     ViewBag.MunicipalityId = new SelectList(CombosHelper.GetMunicipalities(0), "MunicipalityId", "Description");
     ViewBag.StateId        = new SelectList(CombosHelper.GetStates(), "StateId", "Description");
     return(View());
 }
Пример #7
0
        // GET: Products/Create
        public ActionResult Create()
        {
            var user = db.Users.Where(u => u.UserName.Equals(User.Identity.Name)).FirstOrDefault();

            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(user.CompanyId), "CategoryId", "Description");
            //ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name");
            ViewBag.TaxId = new SelectList(CombosHelper.GetTaxes(user.CompanyId), "TaxId", "Description");

            //lemando el objeto product a la vista:
            var product = new Product
            {
                CompanyId = user.CompanyId
            };

            return(View(product));
        }
Пример #8
0
        public ActionResult Create(Product product)
        {
            var user = db.Users.
                       Where(u => u.UserName == User.Identity.Name).
                       FirstOrDefault();

            if (ModelState.IsValid)
            {
                try
                {
                    db.Products.Add(product);
                    db.SaveChanges();

                    if (product.ImageFile != null)
                    {
                        var folder   = "~/Content/Products";
                        var file     = string.Format("{0}.jpg", product.ProductId);
                        var response = FilesHelper.UploadPhoto(product.ImageFile, folder, file);

                        if (response)
                        {
                            var pic = string.Format("{0}/{1}", folder, file);
                            product.Image           = pic;
                            db.Entry(product).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null && ex.InnerException.InnerException != null &&
                        ex.InnerException.InnerException.Message.Contains("_Index"))
                    {
                        ModelState.AddModelError(string.Empty, "The record can't be delete because it has record");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                }
            }
            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(user.CompanyId), "CategoryId", "Description", product.CategoryId);
            ViewBag.TaxId      = new SelectList(CombosHelper.GetTaxes(user.CompanyId), "TaxId", "Description", product.TaxId);
            return(View(product));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RequestInstitute requestInstitute = db.RequestInstitutes.Find(id);

            if (requestInstitute == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoryId     = new SelectList(CombosHelper.GetCategories(), "CategoryId", "Description", requestInstitute.CategoryId);
            ViewBag.ColonyId       = new SelectList(CombosHelper.GetColonies(0), "ColonyId", "Description", requestInstitute.ColonyId);
            ViewBag.MunicipalityId = new SelectList(CombosHelper.GetMunicipalities(0), "MunicipalityId", "Description", requestInstitute.MunicipalityId);
            ViewBag.StateId        = new SelectList(CombosHelper.GetStates(), "StateId", "Description", requestInstitute.StateId);
            return(View(requestInstitute));
        }
        public ActionResult Edit(RequestInstitute requestInstitute)
        {
            if (ModelState.IsValid)
            {
                db.Entry(requestInstitute).State = EntityState.Modified;
                var response = DbHelper.SaveChanges(db);
                if (response.Successfully)
                {
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(string.Empty, response.Message);
            }
            ViewBag.CategoryId     = new SelectList(CombosHelper.GetCategories(), "CategoryId", "Description", requestInstitute.CategoryId);
            ViewBag.ColonyId       = new SelectList(CombosHelper.GetColonies(requestInstitute.ColonyId), "ColonyId", "Description", requestInstitute.ColonyId);
            ViewBag.MunicipalityId = new SelectList(CombosHelper.GetMunicipalities(requestInstitute.MunicipalityId), "MunicipalityId", "Description", requestInstitute.MunicipalityId);
            ViewBag.StateId        = new SelectList(CombosHelper.GetStates(), "StateId", "Description", requestInstitute.StateId);
            return(View(requestInstitute));
        }
Пример #11
0
        public ActionResult Create(Product product)
        {
            var user = db.Users.Where(u => u.UserName.Equals(User.Identity.Name)).FirstOrDefault();

            if (ModelState.IsValid)
            {
                db.Products.Add(product);


                try
                {
                    db.SaveChanges();

                    if (product.ImageFile != null)
                    {
                        var file   = $"{product.ProductId}.jpg";
                        var folder = "~/Content/Products";

                        var response = FileHelper.UploadPhoto(product.ImageFile, folder, file);

                        if (response)
                        {
                            product.Image = $"{folder}/{file}";

                            db.Entry(product).State = EntityState.Modified;

                            db.SaveChanges();
                        }
                    }
                    return(RedirectToAction("Index"));
                }
                catch (Exception)
                {
                    throw;
                }
            }

            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(user.CompanyId), "CategoryId", "Description", product.CategoryId);
            //ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", product.CompanyId);
            ViewBag.TaxId = new SelectList(CombosHelper.GetTaxes(user.CompanyId), "TaxId", "Description", product.TaxId);

            return(View(product));
        }
Пример #12
0
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var product = await db.Products.FindAsync(id);

            if (product == null)
            {
                return(HttpNotFound());
            }

            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(), "CategoryId", "Description", product.CategoryId);
            var view = ToView(product);

            return(View(view));
        }
Пример #13
0
        // GET: Products/Edit/5
        public ActionResult Edit(int?id)
        {
            //var user = db.Users.Where(u=>u.UserName.Equals(User.Identity.Name)).FirstOrDefault();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product product = db.Products.Find(id);

            if (product == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(product.CompanyId), "CategoryId", "Description", product.CategoryId);
            //ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", product.CompanyId);
            ViewBag.TaxId = new SelectList(CombosHelper.GetTaxes(product.CompanyId), "TaxId", "Description", product.TaxId);

            return(View(product));
        }
Пример #14
0
        public ActionResult Edit(Product product)
        {
            if (ModelState.IsValid)
            {
                var pic    = product.Image;
                var folder = "~/Content/Products";

                if (product.ImageFile != null)
                {
                    if (pic == null || pic == string.Empty)
                    {
                        pic = FilesHelper.GetNamePhoto(product.ProductId);
                    }
                    else
                    {
                        pic = pic.Substring(19);
                    }


                    if (pic != null)
                    {
                        pic = FilesHelper.UploadPhoto(product.ImageFile, pic, folder);
                        pic = string.Format("{0}/{1}", folder, pic);
                    }
                }
                product.Image = pic;

                db.Entry(product).State = EntityState.Modified;
                var respon = DBHelper.SaveChanges(db);
                if (!respon.Succeded)
                {
                    ModelState.AddModelError(string.Empty, respon.Message);
                    return(View(product));
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(product.CompanyId), "CategoryId", "Description", product.CategoryId);
            ViewBag.TaxId      = new SelectList(CombosHelper.GetTaxes(product.CompanyId), "TaxId", "Description", product.TaxId);
            return(View(product));
        }
Пример #15
0
        public ActionResult Create(Product product)
        {
            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                var responsse = DBHelper.SaveChanges(db);
                if (!responsse.Succeded)
                {
                    ModelState.AddModelError(string.Empty, responsse.Message);
                    return(View(product));
                }


                if (product.ImageFile != null)
                {
                    var pic    = string.Empty;
                    var folder = "~/Content/Products";
                    pic = FilesHelper.GetNamePhoto(product.ProductId);
                    if (pic != null)
                    {
                        var response = FilesHelper.UploadPhoto(product.ImageFile, pic, folder);
                        product.Image           = string.Format("{0}/{1}", folder, pic);
                        db.Entry(product).State = EntityState.Modified;
                        var respons = DBHelper.SaveChanges(db);
                        if (!responsse.Succeded)
                        {
                            ModelState.AddModelError(string.Empty, responsse.Message);
                            return(View(product));
                        }
                    }
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(user.CompanyId), "CategoryId", "Description", product.CategoryId);
            ViewBag.TaxId      = new SelectList(CombosHelper.GetTaxes(user.CompanyId), "TaxId", "Description", product.TaxId);
            return(View(product));
        }
        public ActionResult Create(RequestInstitute requestInstitute)
        {
            if (ModelState.IsValid)
            {
                requestInstitute.SendDate = DateTime.Now;
                requestInstitute.Status   = "Espera";
                db.RequestInstitutes.Add(requestInstitute);
                var response = DbHelper.SaveChanges(db);
                if (response.Successfully)
                {
                    return(RedirectToAction("Mensaje"));
                }

                ModelState.AddModelError(string.Empty, response.Message);
            }

            ViewBag.CategoryId     = new SelectList(CombosHelper.GetCategories(), "CategoryId", "Description", requestInstitute.CategoryId);
            ViewBag.ColonyId       = new SelectList(CombosHelper.GetColonies(requestInstitute.ColonyId), "ColonyId", "Description", requestInstitute.ColonyId);
            ViewBag.MunicipalityId = new SelectList(CombosHelper.GetMunicipalities(requestInstitute.MunicipalityId), "MunicipalityId", "Description", requestInstitute.MunicipalityId);
            ViewBag.StateId        = new SelectList(CombosHelper.GetStates(), "StateId", "Description", requestInstitute.StateId);
            return(View(requestInstitute));
        }
Пример #17
0
        // GET: Products/Edit/5
        public ActionResult Edit(int?id)
        {
            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            if (user == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var product = db.Products.Find(id);

            if (product == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(user.CompanyId), "CategoryId", "Description", product.CategoryId);
            ViewBag.TaxId      = new SelectList(CombosHelper.GetTaxes(user.CompanyId), "TaxId", "Description", product.TaxId);
            return(View(product));
        }
Пример #18
0
        public ActionResult Edit(Product product)
        {
            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            if (user == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (ModelState.IsValid)
            {
                if (product.ImageFile != null)
                {
                    var folder    = "~/Content/Products";
                    var file      = string.Format("{0}.jpg", product.ProductId);
                    var response2 = FilesHelper.UploadPhoto(product.ImageFile, folder, file);
                    if (response2)
                    {
                        product.Image = string.Format("{0}/{1}", folder, file);;
                    }
                }

                db.Entry(product).State = EntityState.Modified;
                var response = DBHelper.SaveChanges(db);
                if (response.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, response.Message);
                }
            }
            ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(user.CompanyId), "CategoryId", "Description", product.CategoryId);
            ViewBag.TaxId      = new SelectList(CombosHelper.GetTaxes(user.CompanyId), "TaxId", "Description", product.TaxId);
            return(View(product));
        }
Пример #19
0
 public ActionResult Create()
 {
     ViewBag.CategoryId = new SelectList(CombosHelper.GetCategories(), "CategoryId", "Description");
     return(View());
 }