예제 #1
0
        //Insert User Login
        public UserLogin InsertUserLogin(User user)
        {
            try
            {
                UserLogin userLogin = new UserLogin();
                long      userId    = db.Users.Single(v => v.UserName == user.UserName).Id;

                userLogin.LoginDate = DateTime.Now;
                userLogin.FkUser_Id = userId;

                //Check Login Valid
                if (isChecked.Login(user.UserName, user.Password))
                {
                    //Login Success
                    userLogin.IsSuccess = true;
                    //Insert last IsBlock
                    if (db.UserLogins.Where(x => x.FkUser_Id == userId).Count() > 0)
                    {
                        user.IsBlocked = db.Users.Find(userId).IsBlocked;
                    }
                }
                else
                {
                    //Login not Success
                    //Check Last 10 login user If all NotSuccess Or Not
                    int skipCount = db.UserLogins.Where(x => x.FkUser_Id == userId).Count() - 10;
                    if (skipCount > 0)
                    {
                        var userLogins = db.UserLogins.Where(x => x.FkUser_Id == userId).ToList();
                        if (!userLogins.Skip(skipCount).Any(x => x.IsSuccess == true))
                        {
                            user.IsBlocked = true;
                        }
                    }

                    userLogin.IsSuccess = false;
                }

                //التحقق اذا كان المستخدم محظور من قبل الاآدارة
                var User = db.Users.Find(userId);
                //اذا كان محظر من قبل ال
                user.IsBlocked = User.IsBlocked;

                db.UserLogins.Add(userLogin);
                db.SaveChanges();
                return(userLogin);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// User Login
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public User UserLogin(UserVM user)
        {
            try
            {
                UserLogin UserLogin = new UserLogin
                {
                    LoginDate = DateTime.Now,
                    FkUser_Id = user.Id.Value
                };

                var User = db.Users.Find(user.Id.Value);

                //Check Login Valid
                if (db.Users_CheckFromLoginData(user.UserName, user.Password).First().HasValue)
                {
                    //Login Success
                    UserLogin.IsSuccess = true;
                    User.IsSuccessLogin = true;
                }
                else
                {
                    //Login UnSuccess
                    //Check Last 10 login user If all NotSuccess Or Not
                    int skipCount = db.UserLogins.Where(x => x.FkUser_Id == UserLogin.FkUser_Id).Count() - 10;
                    if (skipCount > 0)
                    {
                        var UserLogins = db.UserLogins.Where(x => x.FkUser_Id == UserLogin.FkUser_Id).ToList();
                        if (!UserLogins.Skip(skipCount).Any(x => x.IsSuccess == true))
                        {
                            User.IsBlocked = true;
                        }
                    }
                    UserLogin.IsSuccess = false;
                    User.IsSuccessLogin = false;
                }

                db.UserLogins.Add(UserLogin);
                db.SaveChanges();
                //التحقق باسم المستخدم وكلمة المرور فقط من اجل لا يجب اظهار هل المستخد بلزك او لاء الا فى حالة اذا كان المستخدم يدخل بيانات صحيحة
                User.IsBlocked = CheckedS.IsUserBlocked(user.UserName, user.Password);
                return(User);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #3
0
        public object RentalMark(RentalMark[] rentalCategoryMarks)
        {
            try
            {
                //Get All RentalMark For Check form It
                var AllRentalMark = db.RentalMarks.ToList();
                var Marks         = db.Marks.ToList();
                var Categories    = db.Categories.ToList();



                foreach (RentalMark rT in rentalCategoryMarks)
                {
                    if (rT.State == StateEnumVM.Delete)
                    {
                        var RentalMarkRemove = db.RentalMarks.Find(rT.Id);


                        //Delete
                        db.RentalMarks.Remove(RentalMarkRemove);
                    }
                    else if (rT.State == StateEnumVM.Create)
                    {
                        //New
                        if (rT.FKCategory_Id == 0 || rT.FKCategory_Id == 0)
                        {
                            return new { RequestType = RequestTypeEnumVM.Warning, Message = Token.FiledIsRequired + " >> " + Token.Category + " " + Token.Or + " " + Token.Category, Title = Token.Warning }
                        }
                        ;

                        //just add FKCategory_Id or FKCategory_Id
                        if (rT.FKCategory_Id > 0)
                        {
                            var Category = db.Categories.Find(rT.FKCategory_Id);

                            //Set History Details For Log

                            if (AllRentalMark.Any(x => x.FKMark_Id == rT.FKMark_Id && x.FKCategory_Id == rT.FKCategory_Id))
                            {
                                var Dupl = AllRentalMark.Where(c => c.FKCategory_Id == rT.FKCategory_Id && c.FKMark_Id == rT.FKMark_Id).Single();
                                return(new { RequestType = RequestTypeEnumVM.Warning, Message = Token.CanNotDuplicateRow + " >> " + Dupl.Category.CategoryName + " " + Token.With + " >> " + Dupl.Mark.MarkName, Title = Token.Warning });

                                rT.FKCategory_Id = null;
                            }
                        }
                        else
                        {
                            var Category = db.Categories.Find(rT.FKCategory_Id);

                            if (AllRentalMark.Any(x => x.FKMark_Id == rT.FKMark_Id && x.FKCategory_Id == rT.FKCategory_Id))
                            {
                                var Dupl = AllRentalMark.Where(c => c.FKCategory_Id == rT.FKCategory_Id && c.FKMark_Id == rT.FKMark_Id).Single();
                                return(new { RequestType = RequestTypeEnumVM.Warning, Message = Token.CanNotDuplicateRow + " >> " + Dupl.Category.CategoryName + " " + Token.With + " >> " + Dupl.Mark.MarkName, Title = Token.Warning });
                            }
                        }

                        var Mark = db.Marks.Find(rT.FKMark_Id);


                        db.RentalMarks.Add(rT);
                    }
                }
                db.SaveChanges();
                return(new { RequestType = RequestTypeEnumVM.Success, Message = Token.SaveChange, Title = Token.Success });
            }
            catch (Exception ex)
            {
                return(new { RequestType = RequestTypeEnumVM.Error, Message = Token.NotSaveChange, Title = Token.Error });
            }
        }