Ejemplo n.º 1
0
        public ActionResult Create()
        {
            User loggedUser = Session["LoggedUser"] as User;

            var users       = _uow.UserManager.ListAll(x => x.IsActive && x.StoreId == loggedUser.StoreId).OrderBy(x => x.FirstName).ToList();
            var departments = _uow.DepartmentManager.ListAll(x => x.IsActive && x.StoreId == loggedUser.StoreId).OrderBy(x => x.Name).ToList();
            var breaks      = _uow.BreakManager.ListAll(x => x.IsActive).OrderByDescending(x => x.StartTime).ToList();

            ViewData["Users"]       = VMUser.Parse(users);
            ViewData["Departments"] = VMDepartment.Parse(departments);
            ViewData["Breaks"]      = VMBreak.Parse(breaks);

            return(View());
        }
Ejemplo n.º 2
0
 public IActionResult AddUser(VMUser user)
 {
     try
     {
         var dbUser = user.ToDbUser();
         dbUser.Password = UserService.HashPassword(user.Password);
         UserService.AddUser(dbUser);
         return(Ok(dbUser));
     }
     catch (Exception ex)
     {
         return(BadRequest(new { message = ex.Message }));
     }
 }
Ejemplo n.º 3
0
 public ActionResult UserRegistration(VMUser userDetails)
 {
     if (ModelState.IsValid)
     {
         var email = user.Create(userDetails);
         if (email != string.Empty)
         {
             FormsAuthentication.SetAuthCookie(email, false);
             return(RedirectToAction("Index", "Home"));
         }
         return(View());
     }
     return(View());
 }
        public ActionResult AddUser(VMUser VMuser)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    tblUser user = Session[WebUtil.CURRENT_USER] as tblUser;
                    if (!(user != null))
                    {
                        return(RedirectToAction("RedirectToLogin", "user"));
                    }
                    tblUser Table = (VMuser).TotblUser();

                    if (user.RoleId == 5)
                    {
                        Table.CompanyId = VMuser.CompanyId;
                    }
                    else
                    {
                        Table.CompanyId = user.CompanyId;
                    }
                    Table.CreatedBy   = user.Id;
                    Table.CreatedDate = DateTime.Now;
                    long uno = DateTime.Now.Ticks;
                    if (VMuser.ImageUrl != null)
                    {
                        HttpPostedFileBase file = VMuser.ImageUrl;
                        if (!string.IsNullOrWhiteSpace(file.FileName))
                        {
                            string url  = $"~/DataImages/User/{uno}{file.FileName.Substring(file.FileName.LastIndexOf("."))}";
                            string path = Request.MapPath(url);
                            file.SaveAs(path);
                            Table.ImageUrl = url;
                        }
                    }

                    new UserHandler().AddUser(Table);
                    return(JavaScript("showMessage('success', 'User added Successfully','bottom-right','User', 'Manage')"));
                }
                else
                {
                    return(JavaScript("showMessage('error', 'All fields are required, Please try again','bottom-right','User', 'Manage')"));
                }
            }
            catch (Exception ex)
            {
                return(JavaScript("showMessage('error', 'Failed to Add User, Please Contact to Administrator','bottom-right','User', 'Manage')"));
            }
        }
Ejemplo n.º 5
0
        public IHttpActionResult PutDBUser(Guid id, VMUser user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.UserID)
            {
                return(BadRequest());
            }

            uService.UpdateUser(user);
            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 6
0
        public static VMUser ToVMUser(this ViewUser entity)
        {
            VMUser model = new VMUser();

            model.Id        = entity.Id;
            model.UserName  = entity.UserName;
            model.Email     = entity.Email;
            model.PhoneNo   = entity.PhoneNo;
            model.Password  = entity.Password;
            model.Company   = entity.Company;
            model.RoleName  = entity.Role;
            model.RoleId    = (long)entity.RoleId;
            model.CompanyId = (long)entity.CompanyId;
            model.CNIC      = entity.CNIC;
            return(model);
        }
        public ActionResult Create(VMUser u)
        {
            if (ModelState.IsValid)
            {
                if (um.Create(u))
                {
                    return(Redirect("/Contents/html/parent_reload.htm"));
                }
            }

            ViewBag.Duties      = um.GetDutyList(u.Du_Id);
            ViewBag.Departments = new UDepartment().List();
            ViewBag.Roles       = new URole().List();

            return(View(u));
        }
Ejemplo n.º 8
0
        public ActionResult DetailUser(String UserID)
        {
            VMUser Result = new VMUser();
            var    list   = user.UserDetail(UserID);
            var    level  = list.UserLevel;

            Result.UserName      = list.UserName;
            Result.UserCategorys = list.UserCategory.ToString();
            Result.UserStates    = list.UserState.ToString();
            if (list.UserCategory == UserRole.InstallAdmin)
            {
                string str = list.UserLevel;
                Result.UserLevel = list.UserLevel.Split(',').ToArray();
            }
            return(Json(Result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 9
0
        protected override void OnBindingContextChanged(VMBase oldViewModel, VMBase newViewModel)
        {
            base.OnBindingContextChanged(oldViewModel, newViewModel);

            VMUser oldVm = oldViewModel as VMUser;

            if (oldVm != null)
            {
                oldVm.Face.OnValueChanged  -= FaceChanged;
                oldVm.Level.OnValueChanged -= LevelChanged;
            }
            if (ViewModel != null)
            {
                ViewModel.Face.OnValueChanged  += FaceChanged;
                ViewModel.Level.OnValueChanged += LevelChanged;
            }
        }
Ejemplo n.º 10
0
        public Boolean Create(VMUser vmModel)
        {
            try
            {
                Int32 uId;
                User  model;

                // 不允许将密码设置为“**********”
                if (vmModel.U_Password == "**********")
                {
                    return(false);
                }

                uId = GetUId();

                model = new User
                {
                    U_Id           = uId,
                    Du_Id          = vmModel.Du_Id,
                    U_IdCardNumber = vmModel.U_IdCardNumber,
                    U_Name         = vmModel.U_Name,
                    U_LoginName    = "LoginName" + uId, //[TOKEN_20160815_1559]
                    //U_LoginName = vmModel.Du_Name, //[TOKEN_20160815_1559]
                    U_Password    = EncryptPassword(vmModel.U_Password),
                    U_Departments = vmModel.U_Departments,
                    U_Roles       = vmModel.U_Roles,
                    U_Remark      = vmModel.U_Remark,
                    U_AddTime     = vmModel.U_AddTime,
                    U_Status      = vmModel.U_Status,
                    U_Sort        = uId
                };

                olsEni.Users.Add(model);
                olsEni.SaveChanges();

                UpdateUserDepartment(model);
                UpdateUserRole(model);

                return(true);
            }
            catch (Exception ex)
            {
                StaticHelper.RecordSystemLog(ex);
                return(false);
            }
        }
Ejemplo n.º 11
0
 public IActionResult UpdateUser(VMUser user)
 {
     try
     {
         if (UserService.GetById(user.Id) == null)
         {
             return(NotFound());
         }
         var dbUser = user.ToDbUser();
         UserService.UpdateUser(dbUser);
         return(Ok(dbUser));
     }
     catch (Exception ex)
     {
         return(BadRequest(new { message = ex.Message }));
     }
 }
Ejemplo n.º 12
0
        public override VMUserEncritpted FindByIdUser(int idUser)
        {
            User   user   = _CRUDManager.Find(row => row.Id == idUser);
            VMUser vmUser = new VMUser()
            {
                Id       = user.Id,
                Name     = user.UserName,
                IdTenant = user.TenantId,
                RoleId   = user.RoleId
            };
            VMUserEncritpted vmUserEncritpted = new VMUserEncritpted(vmUser)
            {
                PasswordHash = user.PasswordHash,
                PasswordSalt = user.PasswordSalt
            };

            return(vmUserEncritpted);
        }
Ejemplo n.º 13
0
        public ActionResult Login(VMUser credential)
        {
            TbUser user = unitOfWork.Users.GetByUserName(credential.UserName);

            if (user == null)
            {
                return(NotFound("user not found"));
            }
            else if (user.Password != credential.Password)
            {
                return(Unauthorized("wrong password"));
            }
            VMUser vmuser       = new VMUser();
            var    tokenhandler = new TokenManager(configuration);

            vmuser.Token = tokenhandler.GenerateToken(user.Id);
            return(Ok(vmuser));
        }
Ejemplo n.º 14
0
        public JsonResult AssignVM(ExecuteVM executeVm, int id)
        {
            var check = _vmUserService.CheckUser(id, executeVm.RoleName);

            if (!check)
            {
                var assignVm = new VMUser();
                assignVm.UserId         = id;
                assignVm.ServiceName    = executeVm.ServiceName;
                assignVm.DeploymentName = executeVm.DeploymentName;
                assignVm.VMName         = executeVm.RoleName;
                _vmUserService.AssignUserToVM(assignVm);
                return(Json("Success"));
            }
            else
            {
                return(Json("This user already has " + executeVm.RoleName));
            }
        }
Ejemplo n.º 15
0
        public static User userFromVMUser(VMUser vmUser)
        {
            User user = new User()
            {
                FirstName               = vmUser.FirstName,
                LastName                = vmUser.LastName,
                Email                   = vmUser.Email,
                ContactInfoes           = contactInfoListFromVMContactInfoList(vmUser.ContactInfos),
                Educations              = educationListFromVMEducationList(vmUser.Education),
                Portfolios              = portfolioListFromVMportfolioList(vmUser.Portfolios),
                Links                   = linkListFromVMLinkList(vmUser.Links),
                TotalViews              = vmUser.TotalViews,
                ViewsSinceLastReport    = vmUser.ViewsSinceLastReport,
                LastDailyReportSendTime = vmUser.LastDailyReportSendTime,
                Id = vmUser.UserId
            };

            return(user);
        }
Ejemplo n.º 16
0
        public ActionResult FacebookCallback(string code)
        {
            var     fb     = new FacebookClient();
            dynamic result = fb.Post("oauth/access_token", new
            {
                client_id     = ConfigurationManager.AppSettings["appId"],
                client_secret = ConfigurationManager.AppSettings["appSecret"],
                redirect_uri  = RediredtUri.AbsoluteUri,
                code          = code
            });

            var accessToken = result.access_token;

            if (accessToken == null)
            {
                return(Redirect("/"));
            }

            fb.AccessToken = accessToken;
            dynamic me = fb.Get("me?fields=link,first_name,currency,last_name,email,gender,locale,timezone,verified,picture,age_range");

            var user = new VMUser
            {
                UserId     = me.id,
                FirstName  = me.first_name,
                LastName   = me.last_name,
                Email      = me.email,
                PictureUrl = me.picture.data.url
            };

            user = UserHeppler.SyncUserToDatabase(user);

            Session["user"] = user;

            FormsAuthenticationTicket authTicket =
                new FormsAuthenticationTicket(1, user.UserId, DateTime.Now, DateTime.Now.AddMinutes(200), true, user.Role, "/");
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
                                               FormsAuthentication.Encrypt(authTicket));

            Response.Cookies.Add(cookie);
            return(Redirect("/"));
        }
Ejemplo n.º 17
0
        internal string SendSMS(VMUser user)
        {
            string number   = "91" + user.Mobile;
            string passCode = RandomString(6);
            String message  = HttpUtility.UrlEncode("Welcome to Yarta Coorg! Your verification code is-" + passCode);

            using (var wb = new WebClient())
            {
                byte[] response = wb.UploadValues(ConfigurationManager.AppSettings["SmsApiUrl"], new NameValueCollection()
                {
                    { "apikey", ConfigurationManager.AppSettings["SmsApiKey"] },
                    { "numbers", number },
                    { "message", message },
                    { "sender", ConfigurationManager.AppSettings["SmsSenderKey"] }
                });
                string result = System.Text.Encoding.UTF8.GetString(response);
                user.VerificationCodeTemp = passCode;
                return(result);
            }
        }
Ejemplo n.º 18
0
        public VMUser Get(Int32 id)
        {
            User   model;
            VMUser vmModel;
            Duty   duty;
            String duName;

            model = olsEni.Users.Single(m =>
                                        m.U_Id == id &&
                                        m.U_Status == (Byte)Status.Available);

            if (null != model.Du_Id)
            {
                duty   = olsEni.Duties.SingleOrDefault(m => m.Du_Id == model.Du_Id);
                duName = duty.Du_Name;
            }
            else
            {
                duName = "";
            }

            vmModel = new VMUser
            {
                U_Id           = model.U_Id,
                Du_Id          = model.Du_Id,
                Du_Name        = duName,
                U_IdCardNumber = model.U_IdCardNumber,
                U_Name         = model.U_Name,
                U_LoginName    = model.U_LoginName,
                U_Password     = "******",
                U_RePassword   = "******",
                U_Departments  = model.U_Departments,
                U_Roles        = model.U_Roles,
                U_Remark       = model.U_Remark,
                U_AddTime      = model.U_AddTime,
                U_Status       = model.U_Status,
                U_Sort         = model.U_Sort
            };

            return(vmModel);
        }
Ejemplo n.º 19
0
        public static VMUser UserFindViewID(string id)
        {
            int ID = int.Parse(id);

            using (PCDB db = new PCDB())
            {
                try
                {
                    var    egitim    = db.Egitim.Where(p => p.UserID == ID).ToList();
                    var    projeler  = db.ProjelerDeneyimler.Where(p => p.UserID == ID).ToList();
                    var    isdeneyim = db.IsDeneyimleri.Where(p => p.UserID == ID).ToList();
                    var    o         = db.User.FirstOrDefault(p => p.UserID == ID);
                    VMUser gonder    = new VMUser
                    {
                        AdSoyad             = o.AdSoyad,
                        Beceriler           = o.Beceriler,
                        Diller              = o.Diller,
                        DogumTarihi         = o.DogumTarihi,
                        Egitimler           = egitim,
                        email               = o.email,
                        facebook            = o.facebook,
                        github              = o.github,
                        linken              = o.linken,
                        Meslek              = o.Meslek,
                        ProjelerDeneyimleri = projeler,
                        Resim               = o.Resim,
                        Sifre               = o.Sifre,
                        Telefon             = o.Telefon,
                        twitter             = o.twitter,
                        website             = o.website,
                        UserID              = o.UserID,
                        IsDeneyimleri       = isdeneyim
                    };
                    return(gonder);
                }
                catch
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 20
0
        public ActionResult UserAdd(VMAddUserInfo addUser)
        {
            VMUser vmUser = new VMUser();

            try
            {
                user.UserAdd(addUser.UserCategory, addUser.UserState, addUser.UserName, addUser.UserPassword, addUser.UserLevel);
                vmUser.msg = "添加成功!";
            }
            catch (Exception ex)
            {
                vmUser.msg = ex.Message;
            }
            vmUser.Userlist = SystemMapper.Userlist(user.UserList());
            vmUser.count    = user.UsersList();
            vmUser.AllPage  = Paging.SumPage(vmUser.count, 10);
            vmUser.NowPage  = addUser.NowPage;
            vmUser.NewPage  = (vmUser.AllPage == 0) ? 0 : vmUser.NowPage + 1;
            vmUser.UserName = "";
            return(Json(vmUser, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 21
0
        protected override void OnBindingContextChanged(VMBase oldViewModel, VMBase newViewModel)
        {
            base.OnBindingContextChanged(oldViewModel, newViewModel);

            VMUser oldVm = oldViewModel as VMUser;

            if (oldVm != null)
            {
                oldVm.Gold.OnValueChanged   -= GoldChanged;
                oldVm.Silver.OnValueChanged -= SilverChanged;
                //oldVm.Ap.OnValueChanged -= ApChanged;
                //oldVm.Level.OnValueChanged -= ApChanged;
            }
            if (ViewModel != null)
            {
                ViewModel.Gold.OnValueChanged   += GoldChanged;
                ViewModel.Silver.OnValueChanged += SilverChanged;
                //ViewModel.Ap.OnValueChanged += ApChanged;
                //ViewModel.Level.OnValueChanged += ApChanged;
            }
        }
Ejemplo n.º 22
0
        protected void LogWithUser(string user, string role, string firstName = "", string lastName = "", string email = "")
        {
            var VMuser = new VMUser()
            {
                UserId     = user,
                FirstName  = firstName,
                LastName   = lastName,
                Email      = email,
                PictureUrl = "",
                Role       = role
            };

            Session["user"] = user;

            FormsAuthenticationTicket authTicket =
                new FormsAuthenticationTicket(1, user, DateTime.Now, DateTime.Now.AddMinutes(200), true, role, "/");
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
                                               FormsAuthentication.Encrypt(authTicket));

            Response.Cookies.Add(cookie);
        }
Ejemplo n.º 23
0
        public ActionResult Index()
        {
            List <VMUser> users = new List <VMUser>();

            foreach (var us in nomadDB.Users)
            {
                VMUser u = new VMUser();
                u.ID        = us.ID;
                u.Name      = us.Name;
                u.Surname   = us.Surname;
                u.Email     = us.Email;
                u.Telephone = us.Telephone;
                u.Password  = us.Password;

                u.Image = us.Image;

                users.Add(u);
            }

            return(View(users));
        }
Ejemplo n.º 24
0
        public Boolean Edit(VMUser vmModel)
        {
            try
            {
                User model;

                model = olsEni.Users.Single(m =>
                                            m.U_Id == vmModel.U_Id &&
                                            m.U_Status == (Byte)Status.Available);

                model.U_Id           = vmModel.U_Id;
                model.Du_Id          = vmModel.Du_Id;
                model.U_IdCardNumber = vmModel.U_IdCardNumber;
                model.U_Name         = vmModel.U_Name;
                model.U_LoginName    = vmModel.U_LoginName;
                model.U_Departments  = vmModel.U_Departments;
                model.U_Roles        = vmModel.U_Roles;
                model.U_Remark       = vmModel.U_Remark;
                model.U_Status       = vmModel.U_Status;
                model.U_Sort         = vmModel.U_Sort;

                if ("**********" != vmModel.U_Password)
                {
                    model.U_Password = EncryptPassword(vmModel.U_Password);
                }

                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                UpdateUserDepartment(model);
                UpdateUserRole(model);

                return(true);
            }
            catch (Exception ex)
            {
                StaticHelper.RecordSystemLog(ex);
                return(false);
            }
        }
Ejemplo n.º 25
0
        public static VMUser GetUserById(string userID)
        {
            VMUser user = null;

            using (AirHelpDBContext context = new AirHelpDBContext())
            {
                var userDB = context.Users.Where(u => u.UserId == userID).SingleOrDefault();
                if (userDB != null)
                {
                    user = new VMUser()
                    {
                        UserId     = userDB.UserId,
                        FirstName  = userDB.FirstName,
                        LastName   = userDB.LastName,
                        Email      = userDB.Email,
                        PictureUrl = userDB.PictureUrl,
                        Role       = userDB.Role
                    };
                }
            }
            return(user);
        }
Ejemplo n.º 26
0
        public ActionResult GetShoppingCart(User user)
        {
            int                 listLength      = 0;
            ShoppingCartDal     scDal           = new ShoppingCartDal();
            List <ShoppingCart> objShoppingCart =
                (from x in scDal.shoppingCart
                 where x.customer == user.UserName
                 select x).ToList <ShoppingCart>();

            foreach (ShoppingCart sc in objShoppingCart)
            {
                listLength++;
            }

            if (listLength == 0)
            {
                objShoppingCart = null;
            }
            VMUser vm = new VMUser(user, objShoppingCart);

            return(View("ShowShoppingCart", vm));
        }
Ejemplo n.º 27
0
        public VMUser GetNew()
        {
            VMUser model;

            model = new VMUser()
            {
                U_Id          = 0,
                Du_Id         = 0,
                Du_Name       = "",
                U_Name        = "",
                U_LoginName   = "LoginName0", //[TOKEN_20160815_1559]
                U_Password    = "",
                U_RePassword  = "",
                U_Departments = "[]",
                U_Roles       = "[]",
                U_Remark      = "",
                U_AddTime     = DateTime.Now,
                U_Status      = (Byte)Status.Available
            };

            return(model);
        }
Ejemplo n.º 28
0
        public ActionResult Edit(long id)
        {
            var loggedUser = this.ViewBag.User as User;

            if (!loggedUser.isAdmin || loggedUser.Id != id)
            {
                this.FlashError("You can only edit your own user");
                return(RedirectToAction("Index"));
            }

            var user = db.Users.Where(m => m.Id == id).FirstOrDefault();

            if (user == null)
            {
                this.FlashError("User not found");
                return(RedirectToAction("Index"));
            }

            VMUser vm = new VMUser();

            vm.Email = user.Email;
            return(View(vm));
        }
Ejemplo n.º 29
0
        public override VMUserEncritpted FindByLogin(string userName, string tenant)
        {
            Tenants tenantencontrado = _CRUDManagerTenant.Find(row => row.URLOrigin == tenant);
            User    user             = _CRUDManager.Find(row => row.UserName == userName && row.TenantId == tenantencontrado.Id && row.Validation == true);

            if (user != null)
            {
                VMUser vmUser = new VMUser()
                {
                    Id       = user.Id,
                    Name     = user.UserName,
                    IdTenant = user.TenantId,
                    RoleId   = user.RoleId
                };
                VMUserEncritpted vmUserEncritpted = new VMUserEncritpted(vmUser)
                {
                    PasswordHash = user.PasswordHash,
                    PasswordSalt = user.PasswordSalt
                };
                return(vmUserEncritpted);
            }
            return(null);
        }
Ejemplo n.º 30
0
        public string Create(VMUser userDetails)
        {
            //if (dbReference.Users.Where(m => m.Email == userDetails.Email).SingleOrDefault()== null)
            if (dbReference.Users.SingleOrDefault(m => m.Email == userDetails.Email) == null)
            {
                if (userDetails.ImageUpload != null)
                {
                    string filename = Path.GetFileName(userDetails.ImageUpload.FileName);
                    filePath = Path.Combine("\\Images\\ProfileImages\\", _customHelper.HashValue(filename.ToString() + DateTime.Now) + Path.GetExtension(filename));
                    title    = _customHelper.HashValue(filename.ToString() + DateTime.Now) + Path.GetExtension(filename);
                    string directoryPath = Path.Combine(HttpContext.Current.Server.MapPath("~/Images/ProfileImages"), title);
                    userDetails.ImageUpload.SaveAs(directoryPath);
                }
                else
                {
                    filePath = "\\Images\\ProfileImages\\default.png";
                    title    = "default.png";
                }
                var _user = new User()
                {
                    Email        = userDetails.Email,
                    Name         = userDetails.Name,
                    Password     = _customHelper.HashValue(userDetails.Password),
                    Mobile       = userDetails.Mobile,
                    CreationTime = DateTime.Now,
                    ImageUrl     = filePath,
                    DateOfBirth  = DateTime.Now,
                    Rank         = 0
                };
                dbReference.Users.Add(_user);
                dbReference.SaveChanges();
                return(userDetails.Email);
            }

            return(null);
        }