コード例 #1
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                UserHelper.CreateUserASP(user.UserName, "User");

                if (user.PhotoFile != null)
                {
                    var pic      = string.Empty;
                    var folder   = "~/Content/Users";
                    var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, string.Format("{0}.jpg", user.UserId));

                    if (response)
                    {
                        pic        = string.Format("{0}/{1}.jpg", folder, user.UserId);
                        user.Photo = pic;
                    }
                }
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.CityId        = new SelectList(ComboHelper.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId     = new SelectList(ComboHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentsId = new SelectList(ComboHelper.GetDepartments(), "DepartmentsId", "Name", user.DepartmentsId);
            return(View(user));
        }
コード例 #2
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                UsersHelper.CreateUserASP(user.UserName, "User");

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

                    var response = FileHelper.PhotoUpload(user.PhotoFile, folder, file);
                    if (response == true)
                    {
                        pic        = string.Format("{0}{1}", folder, file);
                        user.Photo = pic;
                    }
                    //{0} = path (~/Content/Users/)
                    //{1} = archive name
                }
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId        = new SelectList(ComboHelper.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId     = new SelectList(ComboHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentsId = new SelectList(ComboHelper.GetDepartments(), "DepartmentsId", "Name", user.DepartmentsId);
            return(View(user));
        }
コード例 #3
0
 // GET: Users/Create
 public ActionResult Create()
 {
     ViewBag.CityId        = new SelectList(ComboHelper.GetCities(), "CityId", "Name");
     ViewBag.CompanyId     = new SelectList(ComboHelper.GetCompanies(), "CompanyId", "Name");
     ViewBag.DepartmentsId = new SelectList(ComboHelper.GetDepartments(), "DepartmentsId", "Name");
     return(View());
 }
コード例 #4
0
        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 response = FilesHelper.UploadPhoto(company.LogoFile, folder, string.Format("{0}.jpg", company.CompanyId));

                    if (response)
                    {
                        pic          = string.Format("{0}/{1}.jpg", folder, company.CompanyId);
                        company.Logo = pic;
                    }
                }
                db.Entry(company).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId        = new SelectList(ComboHelper.GetCities(), "CityId", "Name", company.CityId);
            ViewBag.DepartmentsId = new SelectList(ComboHelper.GetDepartments(), "DepartmentsId", "Name", company.DepartmentsId);
            return(View(company));
        }
コード例 #5
0
        public ActionResult Edit(Company company)
        {
            if (ModelState.IsValid)
            {
                if (company.LogoFile != null)
                {
                    //configuring the logo path
                    var pic    = string.Empty;
                    var folder = "~/Content/Logos/";
                    var file   = string.Format("{0}.jpg", company.CompanyId);

                    var response = FileHelper.PhotoUpload(company.LogoFile, folder, file);
                    if (response == true)
                    {
                        pic          = string.Format("{0}{1}", folder, file);
                        company.Logo = pic;
                    }

                    //{0} = path (~/Content/Logos/)
                    //{1} = archive name
                }

                //company.Logo = pic;

                db.Entry(company).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CityId        = new SelectList(ComboHelper.GetCities(), "CityId", "Name", company.CityId);
            ViewBag.DepartmentsId = new SelectList(ComboHelper.GetDepartments(), "DepartmentsId", "Name", company.DepartmentsId);
            return(View(company));
        }
コード例 #6
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                if (user.PhotoFile != null)
                {
                    var pic      = string.Empty;
                    var folder   = "~/Content/User";
                    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;
                try
                {
                    var db2         = new ECommerceContext();
                    var currentUser = db2.Users.Find(user.UserId);
                    if (currentUser.Email != user.Email)
                    {
                        UserHelper.UsersHelper.UpdateUserName(currentUser.Email, user.Email);
                    }

                    db2.Dispose();
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (System.Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.InnerException != null &&
                        ex.InnerException.InnerException.Message.Contains("_Index"))
                    {
                        ModelState.AddModelError(string.Empty, "Telefone ou email ja existentes !!");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }

                    ViewBag.CityId         = new SelectList(ComboHelper.GetCities(), "CityId", "Name", user.CityId);
                    ViewBag.CompanyId      = new SelectList(ComboHelper.GetCompanys(), "CompanyId", "Name", user.CompanyId);
                    ViewBag.DepartamentsId = new SelectList(ComboHelper.GetDepartaments(), "DepartamentsId", "Name", user.DepartamentsId);
                    return(View(user));
                }
            }
            ViewBag.CityId         = new SelectList(ComboHelper.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId      = new SelectList(ComboHelper.GetCompanys(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartamentsId = new SelectList(ComboHelper.GetDepartaments(), "DepartamentsId", "Name", user.DepartamentsId);
            return(View(user));
        }
コード例 #7
0
        public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                try
                {
                    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"));
                }
                catch (System.Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.InnerException != null &&
                        ex.InnerException.InnerException.Message.Contains("_Index"))
                    {
                        ModelState.AddModelError(string.Empty, "Não é possivel inserir Compania ou Telefone com o mesmo nome !!");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }

                    ViewBag.CityId         = new SelectList(ComboHelper.GetCities(), "CityId", "Name", company.CityId);
                    ViewBag.DepartamentsId = new SelectList(ComboHelper.GetDepartaments(), "DepartamentsId", "Name", company.DepartamentsId);
                    return(View(company));
                }
            }

            ViewBag.CityId         = new SelectList(ComboHelper.GetCities(), "CityId", "Name", company.CityId);
            ViewBag.DepartamentsId = new SelectList(ComboHelper.GetDepartaments(), "DepartamentsId", "Name", company.DepartamentsId);
            return(View(company));
        }
コード例 #8
0
        // GET: Companies/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Company company = db.Companies.Find(id);

            if (company == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CityId        = new SelectList(ComboHelper.GetCities(), "CityId", "Name", company.CityId);
            ViewBag.DepartmentsId = new SelectList(ComboHelper.GetDepartments(), "DepartmentsId", "Name", company.DepartmentsId);
            return(View(company));
        }
コード例 #9
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(ComboHelper.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId      = new SelectList(ComboHelper.GetCompanys(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartamentsId = new SelectList(ComboHelper.GetDepartaments(), "DepartamentsId", "Name", user.DepartamentsId);
            return(View(user));
        }
コード例 #10
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                if (user.PhotoFile != null)
                {
                    //configuring the logo path
                    var pic    = string.Empty;
                    var folder = "~/Content/Users/";
                    //configuring the logo path
                    var file = string.Format("{0}.jpg", user.UserId);

                    var response = FileHelper.PhotoUpload(user.PhotoFile, folder, file);
                    if (response == true)
                    {
                        pic        = string.Format("{0}{1}", folder, file);
                        user.Photo = pic;
                    }
                    //{0} = path (~/Content/Users/)
                    //{1} = archive name
                }

                var db2         = new ECommerceContext();
                var currentÙser = db2.Users.Find(user.UserId);

                if (currentÙser.UserName != user.UserName)
                {
                    UsersHelper.UpdateUserName(currentÙser.UserName, user.UserName);
                }
                db2.Dispose(); //finish db connection
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CityId        = new SelectList(ComboHelper.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId     = new SelectList(ComboHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentsId = new SelectList(ComboHelper.GetDepartments(), "DepartmentsId", "Name", user.DepartmentsId);
            return(View(user));
        }