Example #1
0
        public ActionResult AddCustomer(Customer customer, string phoneNumber, string password)
        {
            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    if (Request.Files.Count > 0)
                    {
                        var file = Request.Files[Request.Files.Count - 1];

                        if (file != null)
                        {
                            string pic = Path.GetFileName(file.FileName);

                            string extensionFileName = CommonFunction.getExtensionFileName(pic);

                            pic = CommonFunction.hashSHA256(pic) + extensionFileName;

                            string path = Path.Combine(Server.MapPath(Constants.CUS_IMG_URL_ADD), pic);
                            customer.Avatar_URL = pic;

                            file.SaveAs(path);
                        }
                    }
                    else
                    {
                        customer.Avatar_URL = Constants.CUS_IMG_NOAVATAR;
                    }

                    customer.Account.PasswordHash = HashPwdTool.GeneratePassword(password);

                    PhoneNumber phNum = new PhoneNumber();
                    phNum.PhoneNumber1 = phoneNumber;
                    customer.PhoneNumbers.Add(phNum);

                    Role_Account ra = new Role_Account();
                    ra.Role_ID = 3;
                    customer.Account.Role_Account.Add(ra);

                    db.Customers.Add(customer);

                    db.SaveChanges();
                    trans.Commit();

                    TempData["AddCustomerOK"] = "OK";

                    return(RedirectToAction("AddCustomer"));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    trans.Rollback();
                    return(View());
                }
            }
        }
Example #2
0
        public ActionResult CreateCustomer(Customer customer, string TypeAcc, string phoneNumber, string password)
        {
            var TypeList = db.Types.Select(p => p.Type_Name).ToList();

            ViewBag.roleList = TypeList;

            if (ModelState.IsValid)
            {
                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[Request.Files.Count - 1];

                    if (file != null)
                    {
                        string pic = Path.GetFileName(file.FileName);

                        string extensionFileName = CommonFunction.getExtensionFileName(pic);

                        pic = CommonFunction.hashSHA256(pic) + extensionFileName;

                        string path = Path.Combine(Server.MapPath(Constants.CUS_IMG_URL_ADD), pic);
                        customer.Avatar_URL = pic;

                        file.SaveAs(path);
                    }
                }
                else
                {
                    customer.Avatar_URL = Constants.CUS_IMG_NOAVATAR;
                }

                customer.Account.PasswordHash = HashPwdTool.GeneratePassword(password);

                PhoneNumber phNum = new PhoneNumber();
                phNum.PhoneNumber1 = phoneNumber;
                customer.PhoneNumbers.Add(phNum);

                Role_Account ra = new Role_Account();
                ra.Role_ID = 3;
                customer.Account.Role_Account.Add(ra);

                int type = db.Types.Where(p => p.Type_Name == TypeAcc).Select(r => r.Type_ID).SingleOrDefault();
                RealEstateWebsite.Models.Type t = db.Types.Find(type);
                customer.Type = db.Types.Find(t.Type_ID);

                db.Customers.Add(customer);

                db.SaveChanges();
                return(RedirectToAction("Viewcustomer", "Customer"));
            }
            return(View());
        }
Example #3
0
        public ActionResult SignUp(SignUpModel cst, HttpPostedFileBase fileUpload)
        {
            if (ModelState.IsValid)
            {
                //db.Customers.Add(cst);
                //db.SaveChanges();
                if (CheckUserName(cst.UserName))
                {
                    ModelState.AddModelError("", "Username already exists");
                }
                else
                {
                    //string a = HashPwdTool.GeneratePassword("1");
                    var account = new Account();/* { UserName = "******",PasswordHash=a};*/
                    account.UserName     = cst.UserName;
                    account.PasswordHash = HashPwdTool.GeneratePassword(cst.PassWord);
                    var phonenumber = new PhoneNumber();
                    phonenumber.PhoneNumber1 = cst.PhoneNumber;
                    var customer = new Customer();
                    customer.Address   = cst.Address;
                    customer.Email     = cst.Email;
                    customer.Firstname = cst.FirstName;
                    customer.LastName  = cst.LastName;

                    var fileName2 = Path.GetFileName(fileUpload.FileName);
                    //Lưu đường dẫn của file
                    var path2 = Path.Combine(Server.MapPath("~/Images/Customer"), fileName2);
                    if (System.IO.File.Exists(path2))
                    {
                        ViewBag.ThongBao = "Images already exists";
                    }
                    else
                    {
                        fileUpload.SaveAs(path2);
                    }
                    customer.Avatar_URL = fileUpload.FileName;
                    customer.Account    = account;

                    Role_Account r_acc = new Role_Account();
                    r_acc.Account = account;
                    r_acc.Role_ID = 3;

                    customer.PhoneNumbers.Add(phonenumber);
                    db.Customers.Add(customer);
                    db.Role_Account.Add(r_acc);
                    db.SaveChanges();
                    ViewBag.ThongBao = "Signup succcessful";
                }
            }
            return(View("SignUp"));
        }
Example #4
0
        public ActionResult CreateEmp(Employee emp, string RoleAcc, string manager_id, string password1)

        {
            var roleList = db.Roles.Select(p => p.Role_Name).Where(p => p != "Admin" && p != "SuperAdmin").ToList();

            ViewBag.roleList = roleList;
            if (ModelState.IsValid)
            {
                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[Request.Files.Count - 1];

                    if (file != null)
                    {
                        string pic = Path.GetFileName(file.FileName);

                        string extensionFileName = CommonFunction.getExtensionFileName(pic);

                        pic = CommonFunction.hashSHA256(pic) + extensionFileName;

                        string path = Path.Combine(Server.MapPath(Constants.EMP_IMG_URL_ADD), pic);
                        emp.Avatar_URL = pic;

                        file.SaveAs(path);
                    }
                }
                else
                {
                    emp.Avatar_URL = Constants.EMP_IMG_NOAVATAR;
                }



                emp.Account.PasswordHash = HashPwdTool.GeneratePassword(password1);

                int          role = db.Roles.Where(p => p.Role_Name == RoleAcc).Select(r => r.Role_ID).SingleOrDefault();
                Role_Account ra   = new Role_Account();
                ra.Role_ID = role;
                emp.Account.Role_Account.Add(ra);
                db.Employees.Add(emp);
                db.SaveChanges();
                int id = db.Employees.Where(p => p.Account.UserName == emp.Account.UserName).SingleOrDefault().Employee_ID;
                db.USP_AddManager_id(id, Convert.ToInt32(manager_id));
                return(RedirectToAction("ViewEmp", "Adminstrator"));
            }
            return(View());
        }