public IActionResult Register([Bind] UserProfileDto user)
        {
            BillingSystemContext context = new BillingSystemContext();
            var registeredUserName       = context.Users.Where(u => u.UserName.Equals(user.UserName)).SingleOrDefault();

            if (registeredUserName != null)
            {
                ViewBag.Error = "This user is already registered.";
                return(View());
            }
            if (context.Users.Any(u => u.Email == user.Email))
            {
                ViewBag.Error = "This e-mail is already taken.";
                return(View());
            }
            try
            {
                UsersBLL bll = new UsersBLL();

                bll.RegisterUser(user);
                return(RedirectToAction("UserLogin", "Login"));
            }
            catch (Exception ex)
            {
            }

            return(View());
        }
        public ActionResult UserLogin([Bind] Users user)
        {
            BillingSystemContext context = new BillingSystemContext();
            Users userFromBase           = context.Users.FirstOrDefault(u => u.UserName == user.UserName);

            if (userFromBase != null && SecurePasswordHasher.Verify(user.Password, userFromBase.Password))
            {
                UsersBLL      usersBLL   = new UsersBLL();
                UserClaimsDto userRoles  = usersBLL.GetUserClaims(user.UserName);
                var           userClaims = new List <Claim>()
                {
                    new Claim(ClaimTypes.Name, userRoles.UserName),
                    new Claim(ClaimTypes.Email, userRoles.Email)
                };

                foreach (RoleMaster rm in userRoles.Roles)
                {
                    userClaims.Add(new Claim(ClaimTypes.Role, rm.RollName));
                }

                var grandmaIdentity = new ClaimsIdentity(userClaims, "User Identity");

                var userPrincipal = new ClaimsPrincipal(new[] { grandmaIdentity });
                HttpContext.SignInAsync(userPrincipal);

                return(RedirectToAction("Index", "Home"));
            }

            return(View(user));
        }
Пример #3
0
        private List <ClientStatusDTO> FilterByComment(string Comment)
        {
            BillingSystemContext context = new BillingSystemContext();


            List <Client> clients = context.Clients.Include(c => c.ClientZone).Include(c => c.ClientTarif)
                                    .Where(c => c.Comment.ToLower()
                                           .Contains(Comment.ToLower())).ToList();

            List <ClientStatusDTO> clientsDTO = new List <ClientStatusDTO>();

            foreach (Client c in clients)
            {
                ClientStatusDTO newClient = (ClientStatusDTO)ModelToDto <ClientStatusDTO>(c);


                if (newClient.Validity >= DateTime.Now)
                {
                    newClient.Status = "ACTIVE";
                }
                else
                {
                    newClient.Status = "INACTIVE";
                }
                clientsDTO.Add(newClient);
            }

            return(clientsDTO);
        }
Пример #4
0
        public List <ClientStatusDTO> GetInActiveClients()
        {
            BillingSystemContext context = new BillingSystemContext();

            context.Clients.Where(c => c.Validity < DateTime.Now).ToList();

            List <Client> clients = context
                                    .Clients.Include(c => c.ClientTarif)
                                    .Include(c => c.ClientZone)
                                    .ToList();

            List <ClientStatusDTO> clientsDTO = new List <ClientStatusDTO>();

            foreach (Client c in clients)
            {
                ClientStatusDTO newClient = (ClientStatusDTO)ModelToDto <ClientStatusDTO>(c);


                if (newClient.Validity >= DateTime.Now)
                {
                    newClient.Status = "ACTIVE";
                }
                else
                {
                    newClient.Status = "INACTIVE";
                }
                clientsDTO.Add(newClient);
            }

            return(clientsDTO);
        }
Пример #5
0
        public void Add(
            string ClientName,
            string Address,
            string PhoneNumber,
            string Tariff,
            string Zone,
            string PonClient,
            string Comment)
        {
            BillingSystemContext context = new BillingSystemContext();
            int    zone   = context.Zones.FirstOrDefault(z => z.Town == Zone).IDNumber;
            int    tariff = context.Tariffs.FirstOrDefault(t => t.Name == Tariff).IDNumber;
            Client client = new Client()
            {
                Name        = ClientName,
                Adress      = Address,
                ZoneId      = zone,
                IPAdress    = null,
                PhoneNumber = PhoneNumber,
                Comment     = Comment,
                Included    = DateTime.Now,
                Validity    = DateTime.Now,
                TariffId    = tariff
            };
            ClientsDao dao = new ClientsDao();

            dao.Insert(client);
        }
Пример #6
0
        public void DeleteClient(int IDNumber)
        {
            BillingSystemContext context = new BillingSystemContext();
            Client     client            = context.Clients.FirstOrDefault(c => c.IDNumber == IDNumber);
            ClientsDao dao = new ClientsDao();

            dao.Delete(client);
        }
Пример #7
0
        public void DeleteTariff(int id)
        {
            BillingSystemContext context = new BillingSystemContext();
            Tariff tariff = context.Tariffs.FirstOrDefault(t => t.IDNumber == id);

            TariffDao tariffDao = new TariffDao();

            tariffDao.Delete(tariff);
        }
Пример #8
0
        public void DeleteProfile(int id)
        {
            BillingSystemContext context = new BillingSystemContext();

            Profile profile = context.Profiles.FirstOrDefault(p => p.IDNumber == id);

            ProfileDAO dao = new ProfileDAO();

            dao.Delete(profile);
        }
Пример #9
0
        public void DeleteZone(int id)
        {
            BillingSystemContext context = new BillingSystemContext();

            Zone zone = context.Zones.FirstOrDefault(z => z.IDNumber == id);

            ZoneDao dao = new ZoneDao();

            dao.Delete(zone);
        }
Пример #10
0
        public ClientStatusDTO GetClient(int ID)
        {
            BillingSystemContext context = new BillingSystemContext();
            Client client = context.Clients
                            .Include(c => c.ClientTarif)
                            .Include(c => c.ClientZone)
                            .FirstOrDefault(c => c.IDNumber == ID);

            ClientStatusDTO clientDto = (ClientStatusDTO)ModelToDto <ClientStatusDTO>(client);


            return(clientDto);
        }
Пример #11
0
        public UserClaimsDto GetUserClaims(string username)
        {
            UserClaimsDto        userdto = new UserClaimsDto();
            BillingSystemContext context = new BillingSystemContext();
            Users user = context.Users.FirstOrDefault(u => u.UserName == username);

            userdto.UserName = user.UserName;
            userdto.Email    = user.Email;

            userdto.Roles = context.RoleMasters
                            .Where(r => context.UserRoleMappings
                                   .Any(urm => urm.RoleID == r.IDNumber && urm.UserID == user.IDNumber)).ToList();

            return(userdto);
        }
Пример #12
0
        public void Add(
            string Town,
            string Owner)
        {
            BillingSystemContext context = new BillingSystemContext();

            Zone zone = new Zone()
            {
                Town  = Town,
                Owner = Owner
            };

            ZoneDao dao = new ZoneDao();

            dao.Insert(zone);
        }
Пример #13
0
        public void Add(
            string PhoneNumber,
            string Name)
        {
            BillingSystemContext context = new BillingSystemContext();

            Profile profile = new Profile()
            {
                PhoneNumber = PhoneNumber,
                Name        = Name
            };

            ProfileDAO dao = new ProfileDAO();

            dao.Insert(profile);
        }
Пример #14
0
        public void UpdateZone(
            string Town,
            string Owner,
            int IDNumber)
        {
            BillingSystemContext context = new BillingSystemContext();

            Zone zone = new Zone()
            {
                Town     = Town,
                Owner    = Owner,
                IDNumber = IDNumber
            };
            ZoneDao dao = new ZoneDao();

            dao.Update(zone);
        }
Пример #15
0
        public void Add(
            string Name,
            int Price,
            int InternetSpeed)
        {
            BillingSystemContext context = new BillingSystemContext();

            Tariff tariff = new Tariff()
            {
                Name          = Name,
                Price         = Price,
                InternetSpeed = InternetSpeed
            };
            TariffDao tariffDao = new TariffDao();

            tariffDao.Insert(tariff);
        }
Пример #16
0
        public void UpdateTariff(
            string Name,
            int Price,
            int InternetSpeed,
            int IDNumber)
        {
            BillingSystemContext context = new BillingSystemContext();
            Tariff tariff = new Tariff()
            {
                Name          = Name,
                Price         = Price,
                InternetSpeed = InternetSpeed,
                IDNumber      = IDNumber
            };
            TariffDao tariffDao = new TariffDao();

            tariffDao.Update(tariff);
        }
Пример #17
0
        public void UpdateProfile(
            string PhoneNumber,
            string Name,
            int IDNumber)
        {
            BillingSystemContext context = new BillingSystemContext();

            Profile profile = new Profile()
            {
                PhoneNumber = PhoneNumber,
                Name        = Name,
                IDNumber    = IDNumber
            };

            ProfileDAO dao = new ProfileDAO();

            dao.Update(profile);
        }
        public IActionResult ProfileDetails()
        {
            ProfileBLL profileBLL = new ProfileBLL();

            //string userName = this.User.Claims.FirstOrDefault(c => c.Type == "Name").Value;
            string userName = HttpContext.User.FindFirst(ClaimTypes.Name).Value;
            BillingSystemContext context = new BillingSystemContext();
            Users currUser = context.Users.FirstOrDefault(u => u.UserName == userName);

            Profile prof = profileBLL.GetProfile(currUser.ProfileID);

            if (prof == null)
            {
                NotFound();
            }

            return(View(prof));
        }
Пример #19
0
        public Payment RegisterPayment(int ClientId, decimal Amount)
        {
            try
            {
                using (BillingSystemContext context = new BillingSystemContext())
                {
                    DateTime validity = context.Clients.FirstOrDefault(c => c.IDNumber == ClientId).Validity;


                    Tariff tarif = context.Clients
                                   .Include(c => c.ClientTarif)
                                   .FirstOrDefault(c => c.IDNumber == ClientId).ClientTarif;

                    Tariff tarifa = context.Tariffs
                                    .FirstOrDefault(
                        t => t.IDNumber == context.Clients.FirstOrDefault(c => c.TariffId == t.IDNumber).TariffId);


                    decimal tarifPrice = tarifa.Price;
                    decimal amount     = Amount;

                    int months = Convert.ToInt32(amount / tarifPrice);

                    Payment payment = new Payment()
                    {
                        Client = ClientId,
                        Date   = DateTime.Now,
                        Amount = Amount
                    };
                    validity = validity.AddMonths(months);
                    context.Payments.Add(payment);

                    context.Clients.FirstOrDefault(c => c.IDNumber == payment.Client).Validity = validity;

                    context.SaveChanges();
                    return(payment);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #20
0
        public void RegisterUser(UserProfileDto profileDto)
        {
            Profile profile = new Profile();

            profile.Name        = profileDto.Name;
            profile.PhoneNumber = profileDto.PhoneNumber;

            BillingSystemContext context = new BillingSystemContext();

            context.Profiles.Add(profile);
            context.SaveChanges();
            Users user = new Users();

            user.UserName        = profileDto.UserName;
            user.Email           = profileDto.Email;
            user.Password        = SecurePasswordHasher.Hash(profileDto.Password);
            user.ConfirmPassword = SecurePasswordHasher.Hash(profileDto.ConfirmPassword);

            user.ProfileID = profile.IDNumber;
            context.Users.Add(user);

            context.SaveChanges();
        }
Пример #21
0
        public Profile GetProfile(string Name)
        {
            BillingSystemContext context = new BillingSystemContext();

            return(context.Profiles.FirstOrDefault(p => p.Name == Name));
        }
Пример #22
0
        public List <ClientStatusDTO> GetFilteredClients(ClientFilterType FilterType, string Filter)
        {
            if (FilterType == ClientFilterType.Name)
            {
                BillingSystemContext context = new BillingSystemContext();
                List <Client>        clients = context
                                               .Clients.Include(c => c.ClientTarif)
                                               .Include(c => c.ClientZone)
                                               .ToList();

                List <ClientStatusDTO> clientsDTO = new List <ClientStatusDTO>();
                foreach (Client c in clients)
                {
                    ClientStatusDTO newClient = (ClientStatusDTO)ModelToDto <ClientStatusDTO>(c);

                    if (newClient.Validity >= DateTime.Now)
                    {
                        newClient.Status = "ACTIVE";
                    }
                    else
                    {
                        newClient.Status = "INACTIVE";
                    }
                    clientsDTO.Add(newClient);
                }
                FilterByName(Filter);
                return(clientsDTO);
            }
            else if (FilterType == ClientFilterType.Address)
            {
                BillingSystemContext context = new BillingSystemContext();

                List <Client> clients = context
                                        .Clients.Include(c => c.ClientTarif)
                                        .Include(c => c.ClientZone)
                                        .ToList();

                List <ClientStatusDTO> clientsDTO = new List <ClientStatusDTO>();

                foreach (Client c in clients)
                {
                    ClientStatusDTO newClient = (ClientStatusDTO)ModelToDto <ClientStatusDTO>(c);


                    if (newClient.Validity >= DateTime.Now)
                    {
                        newClient.Status = "ACTIVE";
                    }
                    else
                    {
                        newClient.Status = "INACTIVE";
                    }
                    clientsDTO.Add(newClient);
                }
                FilterByAddress(Filter);
                return(clientsDTO);
            }
            else if (FilterType == ClientFilterType.PhoneNumber)
            {
                BillingSystemContext context = new BillingSystemContext();

                List <Client> clients = context
                                        .Clients.Include(c => c.ClientTarif)
                                        .Include(c => c.ClientZone)
                                        .ToList();

                List <ClientStatusDTO> clientsDTO = new List <ClientStatusDTO>();

                foreach (Client c in clients)
                {
                    ClientStatusDTO newClient = (ClientStatusDTO)ModelToDto <ClientStatusDTO>(c);


                    if (newClient.Validity >= DateTime.Now)
                    {
                        newClient.Status = "ACTIVE";
                    }
                    else
                    {
                        newClient.Status = "INACTIVE";
                    }
                    clientsDTO.Add(newClient);
                }
                FilterByPhoneNumber(Filter);
                return(clientsDTO);
            }
            else if (FilterType == ClientFilterType.IPAdress)
            {
                BillingSystemContext context = new BillingSystemContext();

                List <Client> clients = context
                                        .Clients.Include(c => c.ClientTarif)
                                        .Include(c => c.ClientZone)
                                        .ToList();

                List <ClientStatusDTO> clientsDTO = new List <ClientStatusDTO>();

                foreach (Client c in clients)
                {
                    ClientStatusDTO newClient = (ClientStatusDTO)ModelToDto <ClientStatusDTO>(c);


                    if (newClient.Validity >= DateTime.Now)
                    {
                        newClient.Status = "ACTIVE";
                    }
                    else
                    {
                        newClient.Status = "INACTIVE";
                    }
                    clientsDTO.Add(newClient);
                }
                FilterByIPAdress(Filter);
                return(clientsDTO);
            }
            else if (FilterType == ClientFilterType.comment)
            {
                BillingSystemContext context = new BillingSystemContext();

                List <Client> clients = context
                                        .Clients.Include(c => c.ClientTarif)
                                        .Include(c => c.ClientZone)
                                        .ToList();

                List <ClientStatusDTO> clientsDTO = new List <ClientStatusDTO>();

                foreach (Client c in clients)
                {
                    ClientStatusDTO newClient = (ClientStatusDTO)ModelToDto <ClientStatusDTO>(c);


                    if (newClient.Validity >= DateTime.Now)
                    {
                        newClient.Status = "ACTIVE";
                    }
                    else
                    {
                        newClient.Status = "INACTIVE";
                    }
                    clientsDTO.Add(newClient);
                }
                FilterByComment(Filter);
                return(clientsDTO);
            }
            throw new InvalidEnumArgumentException("No such filter type.");
        }
Пример #23
0
        public List <Client> GetExpiringClients()
        {
            BillingSystemContext context = new BillingSystemContext();

            return(context.Clients.Where(c => c.Validity > DateTime.Now.AddDays(-5) && c.Validity <= DateTime.Now).ToList());
        }
Пример #24
0
        public List <Client> GetClientsByTariff(string FilterTariff)
        {
            BillingSystemContext context = new BillingSystemContext();

            return(context.Clients.Include(c => c.TariffId).Where(c => c.ClientTarif.Name == FilterTariff).ToList());
        }
Пример #25
0
        public Zone GetZone(string Name)
        {
            BillingSystemContext context = new BillingSystemContext();

            return(context.Zones.FirstOrDefault(z => z.Town == Name));
        }
Пример #26
0
        public List <Payment> GetPaymetsTimeSpan(DateTime From, DateTime To)
        {
            BillingSystemContext context = new BillingSystemContext();

            return(context.Payments.Where(p => p.Date >= From && p.Date <= To).ToList());
        }
Пример #27
0
        public List <Users> GetUsers()
        {
            BillingSystemContext context = new BillingSystemContext();

            return(context.Users.ToList());
        }
Пример #28
0
        public bool HasExpiredClients()
        {
            BillingSystemContext context = new BillingSystemContext();

            return(context.Clients.Any(c => c.Validity > DateTime.Now));
        }
Пример #29
0
        public List <Client> GetClientsByZone(string Zone)
        {
            BillingSystemContext context = new BillingSystemContext();

            return(context.Clients.Include(c => c.Name).Where(c => c.ClientZone.Town == Zone).ToList());
        }
Пример #30
0
        public List <Client> GetClientsByZoneID(int ZoneId)
        {
            BillingSystemContext context = new BillingSystemContext();

            return(context.Clients.Include(c => c.IDNumber).Where(c => c.ClientZone.IDNumber == ZoneId).ToList());
        }