public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                db.SaveChanges();
                if (company.LogoFile != null)
                {
                    var folder   = "~/Content/Logos";
                    var file     = string.Format("{0}.jpg", company.CompanyId);
                    var response = FilesHelper.UploadPhoto(company.LogoFile, folder, file);
                    if (response)
                    {
                        var pic = string.Format("{0}/{1}", folder, file);
                        company.Logo            = pic;
                        db.Entry(company).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }


                return(RedirectToAction("Index"));
            }

            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(company.DepartmentId), "CityId", "Name", company.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name", company.DepartmentId);
            return(View(company));
        }
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();                                 //meterlo en un try con un mensaje diciendo que no puede haber dos correo iguales
                UsersHelper.CreateUserASP(user.UserName, "User"); // con esta linea validamos que debe crear un usuario


                if (user.PhotoFile != null)
                {
                    var folder   = "~/Content/Users";
                    var file     = string.Format("{0}.jpg", user.UserId);
                    var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file);
                    if (response)
                    {
                        var pic = string.Format("{0}/{1}", folder, file);
                        user.Photo           = pic;
                        db.Entry(user).State = EntityState.Modified;
                        db.SaveChanges();
                    }


                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(user.DepartmentId), "CityId", "Name", user.CityId);
            ViewBag.CompanyId    = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
 // GET: Users/Create
 public ActionResult Create()
 {
     ViewBag.CityId       = new SelectList(CombosHelper.GetCities(0), "CityId", "Name");
     ViewBag.CompanyId    = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name");
     ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name");
     return(View());
 }
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                /* if (user.PhotoFile != null)
                 * {
                 *
                 *   var folder = "~/Content/Users";
                 *   var file = string.Format("{0}.jpg", user.UserId);
                 *   var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file);
                 * }*/

                var db2        = new ECommerceContext();
                var currenUser = db2.Users.Find(user.UserId);
                if (currenUser.UserName != user.UserName)
                {
                    UsersHelper.UpdateUserName(currenUser.UserName, user.UserName);
                }
                db2.Dispose();

                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(user.DepartmentId), "CityId", "Name", user.CityId);
            ViewBag.CompanyId    = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
示例#5
0
 // GET: Cities/Create
 public ActionResult Create()
 {
     ViewBag.DepartmentId = new SelectList
                                (CombosHelper.GetDepatment(),
                                "DepartmentId",
                                "Name");
     return(View());
 }
示例#6
0
        // GET: Warehouses/Create
        public ActionResult Create()
        {
            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(0), "CityId", "Name");
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name");
            var user      = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
            var warahouse = new Warehouse {
                CompanyId = user.CompanyId,
            };

            return(View(warahouse));
        }
示例#7
0
 public ActionResult Edit(Warehouse warehouse)
 {
     if (ModelState.IsValid)
     {
         db.Entry(warehouse).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CityId       = new SelectList(CombosHelper.GetCities(warehouse.DepartmentId), "CityId", "Name", warehouse.CityId);
     ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name", warehouse.DepartmentId);
     return(View(warehouse));
 }
示例#8
0
 public ActionResult Edit([Bind(Include = "CityId,Name,DepartmentId")] City city)
 {
     if (ModelState.IsValid)
     {
         db.Entry(city).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DepartmentId = new SelectList(
         CombosHelper.GetDepatment()
         , "DepartmentId",
         "Name",
         city.DepartmentId);
     return(View(city));
 }
示例#9
0
        // GET: Warehouses/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var warehouse = db.Warehouses.Find(id);

            if (warehouse == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(warehouse.DepartmentId), "CityId", "Name", warehouse.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name", warehouse.DepartmentId);
            return(View(warehouse));
        }
        // GET: Customers/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var customer = db.Customers.Find(id);

            if (customer == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(customer.DepartmentId), "CityId", "Name");
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name");
            return(View(customer));
        }
 public ActionResult Edit(Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         var response = DBHelper.SaveChanges(db);
         if (response.Succeded)
         {
             //TODO: Validate when the customer email change
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError(string.Empty, response.Message);
     }
     ViewBag.CityId       = new SelectList(CombosHelper.GetCities(customer.DepartmentId), "CityId", "Name");
     ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name");
     return(View(customer));
 }
示例#12
0
        public ActionResult Create([Bind(Include = "CityId,Name,DepartmentId")] City city)
        {
            if (ModelState.IsValid)
            {
                db.Cities.Add(city);
                db.SaveChanges();//toca meterle en un try

                return(RedirectToAction("Index"));
            }

            ViewBag.DepartmentId = new SelectList(
                CombosHelper.GetDepatment()
                , "DepartmentId",
                "Name",
                city.DepartmentId);
            return(View(city));
        }
        public ActionResult Create(Customer customer)
        {
            if (ModelState.IsValid)
            {
                using (var transation = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Customers.Add(customer);
                        var response = DBHelper.SaveChanges(db);
                        if (!response.Succeded)
                        {
                            ModelState.AddModelError(string.Empty, response.Message);
                            transation.Rollback();
                            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(customer.DepartmentId), "CityId", "Name");
                            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name");
                        }

                        UsersHelper.CreateUserASP(customer.UserName, "Customer");

                        var user            = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
                        var companyCustomer = new CompanyCustomer
                        {
                            CompanyId  = user.CompanyId,
                            CustomerId = customer.CustomerId,
                        };

                        db.CompanyCustomers.Add(companyCustomer);
                        db.SaveChanges();

                        transation.Commit();
                        return(RedirectToAction("Index"));
                    }
                    catch (Exception ex)
                    {
                        transation.Rollback();
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                }
            }
            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(customer.DepartmentId), "CityId", "Name");
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepatment(), "DepartmentId", "Name");
            return(View(customer));
        }
示例#14
0
        // GET: Cities/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            City city = db.Cities.Find(id);

            if (city == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DepartmentId = new SelectList(
                CombosHelper.GetDepatment()
                , "DepartmentId",
                "Name",
                city.DepartmentId);
            return(View(city));
        }