Ejemplo n.º 1
0
        public int checkLoginAvalability(int posId, string deviceCode, string userName, string password)
        {
            // 1 :  can login-
            //  0 : error
            // -1 : package is expired
            // -2 : device code is not correct
            // -3 : serial is not active
            // -4 : customer server code is wrong
            // -5 : login date is before last login date

            try
            {
                using (incposdbEntities entity = new incposdbEntities())
                {
                    //check support user
                    if (userName == "Support@Increase")
                    {
                        var suppUser = entity.users.Where(u => u.isActive == 1 && u.username == userName && u.password == password && u.isAdmin == true).FirstOrDefault();
                        if (suppUser != null)
                        {
                            return(1);
                        }
                    }
                    //compair login date with last login date for this user
                    var user = entity.users.Where(x => x.username == userName && x.password == password && x.isActive == 1).FirstOrDefault();
                    if (user != null)
                    {
                        var logs = entity.usersLogs.Where(x => x.userId == user.userId).OrderByDescending(x => x.sInDate).FirstOrDefault();
                        if (logs != null && logs.sInDate > DateTime.Now)
                        {
                            return(-5);
                        }
                    }
                    ActivateController ac = new ActivateController();
                    int active            = ac.CheckPeriod();
                    if (active == 0)
                    {
                        return(-1);
                    }
                    else
                    {
                        var tmpObject = entity.posSetting.Where(x => x.posId == posId).FirstOrDefault();
                        if (tmpObject != null)
                        {
                            // check customer code
                            if (tmpObject.posDeviceCode != deviceCode)
                            {
                                return(-2);
                            }
                            //check customer server code
                            ProgramDetailsController pc = new ProgramDetailsController();
                            var programD = pc.getCustomerServerCode();
                            if (programD == null || programD.customerServerCode != ac.ServerID())
                            {
                                return(-4);
                            }
                        }
                        // check serial && package avalilability
                        var serial         = entity.posSetting.Where(x => x.posId == posId && x.posSerials.isActive == true).FirstOrDefault();
                        var programDetails = entity.ProgramDetails.Where(x => x.isActive == true).FirstOrDefault();
                        if (serial == null || programDetails == null)
                        {
                            return(-3);
                        }
                    }

                    return(1);
                }
            }
            catch
            {
                return(0);
            }
        }