public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                db.SaveChanges();

                if (company.LogoFile != null)
                {
                    var pic    = string.Empty;
                    var folder = "~/Content/Logos";
                    var file   = string.Format("{0}.jpg", company.CompanyId);

                    var response = FilesHelper.UploadPhoto(company.LogoFile, folder, file);

                    if (response)
                    {
                        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(), "Cityid", "Name", company.Cityid);
            ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Name", company.DepartamentsId);
            return(View(company));
        }
示例#2
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                UserHelper.CreateUserASP(user.UserName, "User");

                //tratamento de imagem
                if (user.PhotoFile != null)
                {
                    var pic    = string.Empty;
                    var folder = "~/Content/Users";
                    var file   = string.Format("{0}.jpg", user.UserId);

                    var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file);

                    if (response)
                    {
                        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(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId      = new SelectList(CombosHelper.GetCompanys(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Name", user.DepartamentsId);
            return(View(user));
        }
示例#3
0
 // GET: Users/Create
 public ActionResult Create()
 {
     ViewBag.CityId         = new SelectList(CombosHelper.GetCities(), "CityId", "Name");
     ViewBag.CompanyId      = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name");
     ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Name");
     return(View());
 }
示例#4
0
 // GET: Cities/Create
 public ActionResult Create()
 {
     //List<Departaments> list = CriarRegistroZero(db.Departaments.ToList());
     ///ViewBag.DepartamentsId = new SelectList(list.OrderBy(x => x.DepartamentsId).ToList(), "DepartamentsId", "Nome");
     ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Nome");
     return(View());
 }
示例#5
0
 // GET: Users/Create
 public ActionResult Create()
 {
     //precisa trocar o db.Cities pelo metodo criado no CombosHelper pra chamar a lista oredenada
     ViewBag.CityId         = new SelectList(CombosHelper.GetCities(), "CityId", "Name");
     ViewBag.CompanyId      = new SelectList(CombosHelper.GetCompanys(), "CompanyId", "Name");
     ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Name");
     return(View());
 }
示例#6
0
 public ActionResult Edit([Bind(Include = "CityId,Name,DepartamentsId")] City city)
 {
     if (ModelState.IsValid)
     {
         db.Entry(city).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Name", city.DepartamentsId);
     return(View(city));
 }
示例#7
0
        public ActionResult Create([Bind(Include = "CityId,Name,DepartamentsId")] City city)
        {
            if (ModelState.IsValid)
            {
                db.Cities.Add(city);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Name");
            return(View(city));
        }
示例#8
0
        public ActionResult Create([Bind(Include = "CompanyId,Name,Address,Phone,Logo,DepartamentsId,CityId")] Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId         = new SelectList(CombosHelper.GetCities(), "CityId", "Name", company.CityId);
            ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Name", company.DepartamentsId);
            return(View(company));
        }
示例#9
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.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Name", city.DepartamentsId);
            return(View(city));
        }
示例#10
0
        // GET: Users/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User user = db.Users.Find(id);

            if (user == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CityId         = new SelectList(CombosHelper.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId      = new SelectList(CombosHelper.GetCompanys(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Name", user.DepartamentsId);
            return(View(user));
        }
示例#11
0
        public ActionResult Create([Bind(Include = "CityId,Nome,DepartamentsId")] City city)
        {
            if (ModelState.IsValid)
            {
                if (city.DepartamentsId is 0)
                {
                    View(city);
                }
                ;
                db.Cities.Add(city);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            //List<Departaments> list = CriarRegistroZero(db.Departaments.ToList());
            ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Nome", city.DepartamentsId);
            return(View(city));
        }
示例#12
0
        public ActionResult Edit(Company company)
        {
            if (ModelState.IsValid)
            {
                var pic    = string.Empty;
                var folder = "~/Content/Logos";

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

                db.Entry(company).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CityId         = new SelectList(CombosHelper.GetCities(), "CityId", "Nome", company.CityId);
            ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Nome", company.DepartamentsId);
            return(View(company));
        }
示例#13
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                if (user.PhotoFile != null)
                {
                    var pic    = string.Empty;
                    var folder = "~/Content/Users";
                    var file   = string.Format("{0}.jpg", user.UserId);

                    var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file);

                    if (response)
                    {
                        pic        = string.Format("{0}/{1}", folder, file);
                        user.Photo = pic;
                    }
                }

                var db2         = new EcommerceContext();
                var currentUser = db2.Users.Find(user.UserId);
                if (currentUser.UserName != user.UserName)
                {
                    UserHelper.UpdateUserName(currentUser.UserName, user.UserName);
                }
                db2.Dispose();
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            ViewBag.CityId         = new SelectList(CombosHelper.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId      = new SelectList(CombosHelper.GetCompanys(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Name", user.DepartamentsId);
            return(View(user));
        }
示例#14
0
 public ActionResult Edit(User user)
 {
     if (ModelState.IsValid)
     {
         if (user.PhotoFile != null)
         {
             var pic    = string.Empty;
             var folder = "~/Content/Users";
             var file   = string.Format("{0}.jpg", user.UserId);
             if (FilesHelper.UploadPhoto(user.PhotoFile, folder, file))
             {
                 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(), "CityId", "Name");
     ViewBag.CompanyId      = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name");
     ViewBag.DepartamentsId = new SelectList(CombosHelper.GetDepartaments(), "DepartamentsId", "Name");
     return(View(user));
 }