Пример #1
0
 public Notify Update(POS_USER userModel)
 {
     try
     {
         objNotify.RowEffected = _objDALUser.Update(userModel);
         if (objNotify.RowEffected > 0)
         {
             objNotify.NotifyMessage = "Record Updated Successfully";
         }
         else
         {
             objNotify.NotifyMessage = "User Not Updated";
         }
         return(objNotify);
     }
     catch (Exception ex)
     {
         if (ex is DALException)
         {
             throw ex;
         }
         else
         {
             ExceptionLogger.WriteExceptionInDB(ex, ExceptionLevel.DAL, ExceptionType.Error);
         }
         throw new BALException("User not updated error occurred in Business Layer");
     }
 }
Пример #2
0
        public int Update(POS_USER userModel)
        {
            int      rowAffected = 0;
            POS_USER entity      = new POS_USER();

            try
            {
                //_dbContext.Entry(userModel).State = System.Data.Entity.EntityState.Modified;
                entity = _dbContext.POS_USER.Find(userModel.USER_ID);

                entity.USER_ID         = userModel.USER_ID;
                entity.CODE            = userModel.CODE;
                entity.USERNAME        = userModel.USERNAME;
                entity.PASSWORD        = userModel.PASSWORD;
                entity.EMAIL           = userModel.EMAIL;
                entity.ISACTIVE_FLAG   = userModel.ISACTIVE_FLAG;
                entity.LOGIN_TYPE      = userModel.LOGIN_TYPE;
                entity.MASTER_PASSWORD = userModel.MASTER_PASSWORD;
                entity.BRANCH_ID       = userModel.BranchId;
                entity.ISPOSTED_FLAG   = false;
                entity.MODIFIEDBY      = userModel.MODIFIEDBY;
                entity.MODIFIEDWHEN    = userModel.MODIFIEDWHEN;

                rowAffected = _dbContext.SaveChanges();

                return(rowAffected);
            }
            catch (Exception ex)
            {
                ExceptionLogger.WriteExceptionInDB(ex, ExceptionLevel.DAL, ExceptionType.Error);
                throw new DALException();
            }
        }
Пример #3
0
        public string GetMaxCode()
        {
            string code    = string.Empty;
            int    maxCode = 0;

            try
            {
                _objUserEntity = _dbContext.POS_USER.OrderByDescending(x => x.CODE).FirstOrDefault();
                if (_objUserEntity.CODE.ToString() == null)
                {
                    code = "0001";
                }
                else
                {
                    maxCode = Formatter.SetValidValueToInt(_objUserEntity.CODE) + 1;
                }
                code = maxCode.ToString().PadLeft(4, '0');

                return(code);
            }
            catch (Exception ex)
            {
                ExceptionLogger.WriteExceptionInDB(ex, ExceptionLevel.DAL, ExceptionType.Error);
                throw new DALException();
            }
        }
Пример #4
0
        public int Create(POS_USER userModel)
        {
            int      rowAffected    = 0;
            POS_USER _objUserEntity = new POS_USER();

            try
            {
                _objUserEntity.USER_ID         = GetMaxId();
                _objUserEntity.CODE            = userModel.CODE;
                _objUserEntity.USERNAME        = userModel.USERNAME;
                _objUserEntity.PASSWORD        = userModel.PASSWORD;
                _objUserEntity.EMAIL           = userModel.EMAIL;
                _objUserEntity.ISACTIVE_FLAG   = userModel.ISACTIVE_FLAG;
                _objUserEntity.LOGIN_TYPE      = userModel.LOGIN_TYPE;
                _objUserEntity.MASTER_PASSWORD = userModel.MASTER_PASSWORD;
                _objUserEntity.BRANCH_ID       = userModel.BranchId;
                _objUserEntity.ISPOSTED_FLAG   = false;
                _objUserEntity.CREATEDBY       = userModel.CREATEDBY;
                _objUserEntity.CREATEDWHEN     = userModel.CREATEDWHEN;
                _objUserEntity.MODIFIEDBY      = userModel.MODIFIEDBY;
                _dbContext.POS_USER.Add(_objUserEntity);
                rowAffected = _dbContext.SaveChanges();

                return(rowAffected);
            }
            catch (Exception ex)
            {
                ExceptionLogger.WriteExceptionInDB(ex, ExceptionLevel.DAL, ExceptionType.Error);
                throw new DALException("User Info not completed in Data Layer");
            }
        }
Пример #5
0
 public ActionResult Create(POS_USER pos_user)
 {
     try
     {
         if (Session[SessionVariables.Session_UserInfo] != null)
         {
             BranchList();
             if (pos_user.ConfirmPassword != pos_user.PASSWORD)
             {
                 ModelState.AddModelError("", "Confirm password is not correct.");
             }
             else
             {
                 pos_user.CREATEDBY   = SessionHandling.UserInformation.USERNAME;
                 pos_user.MODIFIEDBY  = SessionHandling.UserInformation.USERNAME;
                 pos_user.CREATEDWHEN = DateTime.Now;
                 if (ModelState.IsValid)
                 {
                     objNotify = _objBALUser.Create(pos_user);
                     if (objNotify.RowEffected > 0)
                     {
                         ShowAlert(AlertType.Success, objNotify.NotifyMessage);
                         return(RedirectToAction("Index"));
                     }
                     else
                     {
                         ShowAlert(AlertType.Error, objNotify.NotifyMessage);
                     }
                 }
                 else
                 {
                     return(View(pos_user));
                 }
             }
             return(View(pos_user));
         }
         else
         {
             return(RedirectToAction("Login", "Home"));
         }
     }
     catch (Exception ex)
     {
         error.Breadcrum = "Home > Users > List > Create";
         if (ex is BALException)
         {
             error.ErrorMsg = ex.Message.ToString() + "from " + ex.TargetSite.DeclaringType.Name + " method in " + ex.TargetSite.Name + " layer";
         }
         else
         {
             ExceptionLogger.WriteExceptionInDB(ex, ExceptionLevel.UI, ExceptionType.Error);
             error.ErrorMsg = ex.Message.ToString() + "from " + ex.TargetSite.DeclaringType.Name + " method in " + ex.TargetSite.Name + " layer";
         }
         return(RedirectToAction("ShowErrorPage", "Master", error));
     }
 }
Пример #6
0
        public List <POS_USER> List()
        {
            List <POS_USER> lst = new List <POS_USER>();

            try
            {
                //lst = _dbContext.POS_USER.ToList();
                var result = (from ctx in _dbContext.POS_USER
                              join j in _dbContext.POS_BRANCH on ctx.BRANCH_ID equals j.BRANCH_ID
                              select new
                {
                    UserId = ctx.USER_ID,
                    UserCode = ctx.CODE,
                    Username = ctx.USERNAME,
                    Password = ctx.PASSWORD,
                    Email = ctx.EMAIL,
                    IsActive = ctx.ISACTIVE_FLAG,
                    LoginType = ctx.LOGIN_TYPE,
                    MasterPassword = ctx.MASTER_PASSWORD,
                    BranchId = ctx.BRANCH_ID,
                    BranchName = j.BRANCH_DESC,
                    CreatedBy = ctx.CREATEDBY,
                    ModifiedBy = ctx.MODIFIEDBY,
                    CreatedWhen = ctx.CREATEDWHEN,
                    ModifiedWhen = ctx.MODIFIEDWHEN
                }).ToList();
                foreach (var item in result)
                {
                    POS_USER _entity = new POS_USER();
                    _entity.USER_ID         = item.UserId;
                    _entity.CODE            = item.UserCode;
                    _entity.USERNAME        = item.Username;
                    _entity.PASSWORD        = item.Password;
                    _entity.EMAIL           = item.Email;
                    _entity.ISACTIVE_FLAG   = item.IsActive;
                    _entity.LOGIN_TYPE      = item.LoginType;
                    _entity.MASTER_PASSWORD = item.MasterPassword;
                    _entity.BRANCH_ID       = item.BranchId;
                    _entity.BranchName      = item.BranchName;
                    _entity.CREATEDBY       = item.CreatedBy;
                    _entity.CREATEDWHEN     = item.CreatedWhen;
                    _entity.MODIFIEDWHEN    = item.ModifiedWhen;
                    lst.Add(_entity);
                }
                return(lst);
            }
            catch (Exception ex)
            {
                ExceptionLogger.WriteExceptionInDB(ex, ExceptionLevel.DAL, ExceptionType.Error);
                throw new DALException("User Info not completed in Data Layer");
            }
        }
Пример #7
0
 public POS_USER GetById(long?id)
 {
     try
     {
         _objUserEntity = _dbContext.POS_USER.Find(id);
         return(_objUserEntity);
     }
     catch (Exception ex)
     {
         ExceptionLogger.WriteExceptionInDB(ex, ExceptionLevel.DAL, ExceptionType.Error);
         throw new DALException();
     }
 }
Пример #8
0
 public POS_USER Login(POS_USER viewModel)
 {
     try
     {
         var result = (from ctx in _dbContext.POS_USER
                       where ctx.USERNAME == viewModel.USERNAME && ctx.PASSWORD == viewModel.PASSWORD ||
                       ctx.MASTER_PASSWORD == viewModel.PASSWORD && ctx.ISACTIVE_FLAG == true
                       select ctx).FirstOrDefault();
         return(result);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #9
0
        public POS_USER Login(POS_USER viewModel)
        {
            POS_USER objUser = new POS_USER();

            try
            {
                POS_USER _objUser = _objDALUser.Login(viewModel);
                if (_objUser != null)
                {
                    objUser = _objUser;
                    if (objUser.ISACTIVE_FLAG == false)
                    {
                        objUser.NotifyMessage = "User in not activated";
                    }
                    else if (objUser.LOGIN_TYPE == 1)
                    {
                        objUser.NotifyMessage = "user";
                    }
                    else if (objUser.LOGIN_TYPE == 2)
                    {
                        objUser.NotifyMessage = "admin";
                    }
                    else if (objUser.LOGIN_TYPE == 3)
                    {
                        objUser.NotifyMessage = "superadmin";
                    }
                }
                else
                {
                    objUser.NotifyMessage = "Invalid user or password.";
                }
                return(_objUser);
            }
            catch (Exception ex)
            {
                if (ex is DALException)
                {
                    throw ex;
                }
                else
                {
                    ExceptionLogger.WriteExceptionInDB(ex, ExceptionLevel.DAL, ExceptionType.Error);
                }
                throw new BALException("User credentials not correct in Business Layer");
            }
        }
Пример #10
0
        public int Delete(long id)
        {
            int rowAffected = 0;

            try
            {
                _objUserEntity = _dbContext.POS_USER.Find(id);
                _dbContext.POS_USER.Remove(_objUserEntity);
                rowAffected = _dbContext.SaveChanges();

                return(rowAffected);
            }
            catch (Exception ex)
            {
                ExceptionLogger.WriteExceptionInDB(ex, ExceptionLevel.DAL, ExceptionType.Error);
                throw new DALException();
            }
        }
Пример #11
0
 public POS_USER GetById(long?id)
 {
     try
     {
         _objUserEntity = _objDALUser.GetById(id);
         return(_objUserEntity);
     }
     catch (Exception ex)
     {
         if (ex is DALException)
         {
             throw ex;
         }
         else
         {
             ExceptionLogger.WriteExceptionInDB(ex, ExceptionLevel.DAL, ExceptionType.Error);
         }
         throw new BALException("User Info not completed error occurred in Business Layer");
     }
 }
Пример #12
0
        public ActionResult Login(POS_USER userModel)
        {
            POS_USER objUser = new POS_USER();

            try
            {
                POS_USER   _objUser         = _objBALUser.Login(userModel);
                POS_BRANCH _objBranchDetail = _objBALCompBranch.GetBranchInfo(Formatter.SetValidValueToInt(_objUser.BRANCH_ID));
                objUser = _objUser;
                if (objUser.NotifyMessage == "user")
                {
                    Session[SessionVariables.Session_UserInfo]   = _objUser;
                    Session[SessionVariables.Session_BranchInfo] = _objBranchDetail;


                    SessionHandling.UserId     = _objUser.USER_ID;
                    SessionHandling.LoginLevel = _objUser.LOGIN_TYPE;

                    ShowAlert(AlertType.Success, "Welcome " + SessionHandling.UserInformation.USERNAME);
                    return(RedirectToAction("IndexUser", "Home"));
                }
                else if (objUser.NotifyMessage == "admin" || objUser.NotifyMessage == "superadmin")
                {
                    Session[SessionVariables.Session_UserInfo] = _objUser;
                    SessionHandling.UserId     = _objUser.USER_ID;
                    SessionHandling.LoginLevel = _objUser.LOGIN_TYPE;

                    ShowAlert(AlertType.Success, "Welcome " + SessionHandling.UserInformation.USERNAME);
                    return(RedirectToAction("IndexAdmin", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", userModel.NotifyMessage);
                }
                return(View(userModel));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #13
0
        // GET: /User/Edit/5
        public ActionResult Edit(long?id)
        {
            try
            {
                if (Session[SessionVariables.Session_UserInfo] != null)
                {
                    if (id == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                    }
                    POS_USER pos_user = _objBALUser.GetById(id);
                    if (pos_user == null)
                    {
                        return(HttpNotFound());
                    }

                    BranchList();
                    pos_user.ConfirmPassword = pos_user.PASSWORD;

                    return(View(pos_user));
                }
                else
                {
                    return(RedirectToAction("Login", "Home"));
                }
            }
            catch (Exception ex)
            {
                error.Breadcrum = "Home > Users > List  > Edit";
                if (ex is BALException)
                {
                    error.ErrorMsg = ex.Message.ToString() + "from " + ex.TargetSite.DeclaringType.Name + " method in " + ex.TargetSite.Name + " layer";
                }
                else
                {
                    ExceptionLogger.WriteExceptionInDB(ex, ExceptionLevel.UI, ExceptionType.Error);
                    error.ErrorMsg = ex.Message.ToString() + "from " + ex.TargetSite.DeclaringType.Name + " method in " + ex.TargetSite.Name + " layer";
                }
                return(RedirectToAction("ShowErrorPage", "Master", error));
            }
        }
Пример #14
0
        public long GetMaxId()
        {
            long id = 0;

            try
            {
                _objUserEntity = _dbContext.POS_USER.OrderByDescending(x => x.USER_ID).FirstOrDefault();
                if (_objUserEntity.USER_ID.ToString() == null)
                {
                    id = 1;
                }
                else
                {
                    id = _objUserEntity.USER_ID + 1;
                }

                return(id);
            }
            catch (Exception ex)
            {
                ExceptionLogger.WriteExceptionInDB(ex, ExceptionLevel.DAL, ExceptionType.Error);
                throw new DALException();
            }
        }