Пример #1
0
        public int UpdateAdmins(Login EditLog, string UserName, int Id)
        {
            List <Login> log       = new List <Login>();
            int          returnVal = 0;

            try
            {
                using (var db = new TestDetailContext())
                {
                    AspNetUsers adminEntity = new AspNetUsers();
                    adminEntity = db.AspNetUsers.FirstOrDefault(x => x.UserName == EditLog.UserName);
                    if (adminEntity != null)
                    {
                        adminEntity.Id       = EditLog.Id;
                        adminEntity.UserName = EditLog.UserName;
                        adminEntity.FullName = EditLog.FullName;
                        adminEntity.Email    = EditLog.Email;
                        db.AspNetUsers.Update(adminEntity);
                    }
                    returnVal = db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(returnVal);
        }
Пример #2
0
        public List <Login> GetAdmins()
        {
            List <Login> log = new List <Login>();

            try
            {
                using (var db = new TestDetailContext())
                {
                    Login lg;
                    foreach (var Adm in db.AspNetUsers.ToList())
                    {
                        lg          = new Login();
                        lg.UserName = Adm.UserName;
                        lg.FullName = Adm.FullName;
                        lg.Email    = Adm.Email;

                        log.Add(lg);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                //throw;
            }
            return(log);
        }
Пример #3
0
        public Login Authenticate(Login Model)
        {
            List <Login> users = new List <Login>();

            using (var db = new TestDetailContext())
            {
                Login lg;
                foreach (var Adm in db.AspNetUsers.ToList())
                {
                    lg              = new Login();
                    lg.UserName     = Adm.UserName;
                    lg.FullName     = Adm.FullName;
                    lg.Email        = Adm.Email;
                    lg.PasswordHash = Adm.PasswordHash;
                    users.Add(lg);
                }
            }
            bool IsvalidPassword = false;
            var  user            = users.SingleOrDefault(x => x.UserName == Model.UserName && x.PasswordHash == Model.PasswordHash);

            if (user != null)
            {
                // IsvalidPassword = BCrypt.Net.BCrypt.Verify(Model.Password, user.Password);
            }

            if (user == null)
            {
                return(null);
            }

            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(_appSettings.Key);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new System.Security.Claims.ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Name, user.UserName.ToString()),
                    new Claim(ClaimTypes.Role, "Admin"),
                    //new Claim(ClaimTypes.Version, "V3.1")
                }),
                Expires            = DateTime.UtcNow.AddMinutes(300),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token = tokenHandler.CreateToken(tokenDescriptor);

            user.Token        = tokenHandler.WriteToken(token);
            user.PasswordHash = null;

            return(user);
        }
Пример #4
0
        public int AddAdmin(Login login)
        {
            int          returnVal = 0;
            List <Login> asps      = new List <Login>();

            try
            {
                using (var db = new TestDetailContext())
                {
                    // aspNet.PasswordHash = BCrypt.Net.BCrypt.HashPassword(aspNet.PasswordHash);
                    Login users;
                    foreach (var adm in db.AspNetUsers.ToList())
                    {
                        users              = new Login();
                        users.UserName     = adm.UserName;
                        users.PasswordHash = adm.PasswordHash;
                        asps.Add(users);
                    }
                    AspNetUsers AdminEntity = new AspNetUsers();
                    AdminEntity.UserName     = login.UserName;
                    AdminEntity.Email        = login.Email;
                    AdminEntity.PasswordHash = login.PasswordHash;
                    AdminEntity.FullName     = login.FullName;

                    bool AdminNameexist = asps.Any(x => x.UserName.ToLower() == AdminEntity.UserName.ToLower());

                    if (AdminNameexist == true)
                    {
                        returnVal = -1;
                    }

                    if (AdminNameexist == false)
                    {
                        db.AspNetUsers.Add(AdminEntity);
                        returnVal = db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(returnVal);
        }
Пример #5
0
        public Login GetAdminByID(string name)
        {
            Login lg = new Login();

            try
            {
                using (var db = new  TestDetailContext())
                {
                    var Adm = db.AspNetUsers.Where(x => x.UserName == name).SingleOrDefault();
                    if (Adm != null)
                    {
                        lg.UserName = Adm.UserName;
                        lg.FullName = Adm.FullName;
                        lg.Email    = Adm.Email;
                    }
                    return(lg);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
Пример #6
0
        public List <Invoice> GetInvoices()
        {
            List <Invoice> invoices = new List <Invoice>();

            try
            {
                TestDetailContext db      = new TestDetailContext();
                List <InvoiceTbl> inv     = new List <InvoiceTbl>();
                List <InvoiceTbl> invdata = db.InvoiceTbl.ToList();
                {
                    Models.Invoice Invoices;

                    int i = 0;

                    foreach (var Inv in invdata)
                    {
                        Invoices = new Models.Invoice();

                        var Cust = db.CustomerTbl.FirstOrDefault(x => x.CustomerId == Inv.CustomerId);
                        Invoices.DateOfMonthInvoice = new DateTime(Inv.InvoiceDate.Year, Inv.InvoiceDate.Month, 11);
                        Invoices.DateOfMonth        = Invoices.DateOfMonthInvoice;

                        if (Cust != null)
                        {
                            Invoices.CustomerID   = Inv.CustomerId;
                            Invoices.CustomerName = Cust.CustomerName;
                        }

                        Invoices.NoOfInvoices = 1;
                        Boolean b = false;


                        foreach (var a in invoices)
                        {
                            if (a.DateOfMonthInvoice == Invoices.DateOfMonthInvoice && a.CustomerID == Invoices.CustomerID)
                            {
                                a.Sales        = Convert.ToInt32(Inv.InvoiceAmount) + a.Sales;
                                a.NoOfInvoices = a.NoOfInvoices + 1;
                                b = true;
                            }
                        }

                        if (b == false)
                        {
                            Invoices.Sales = Convert.ToInt32(Inv.InvoiceAmount);
                            i++;
                            // Invoice1.ID = i;
                            invoices.Add(Invoices);
                        }
                    }

                    List <PaymentTbl> payments = new List <PaymentTbl>();
                    List <PaymentTbl> paydata  = db.PaymentTbl.ToList();

                    foreach (var Pay in paydata)
                    {
                        Invoices = new Models.Invoice();

                        var Inv = db.InvoiceTbl.FirstOrDefault(x => x.InvoiceId == Pay.InvoiceId);

                        var Cust = db.CustomerTbl.FirstOrDefault(x => x.CustomerId == Inv.CustomerId);

                        if (Pay != null)
                        {
                            Invoices.DateOfMonthPay = new DateTime(Pay.PaymentDate.Year, Pay.PaymentDate.Month, 11);
                            Invoices.DateOfMonth    = Invoices.DateOfMonthPay;
                            // Invoice1.Month = Invoice1.DateOfMonth.ToString("MMM-yy");
                        }

                        if (Cust != null)
                        {
                            Invoices.CustomerID   = Cust.CustomerId;
                            Invoices.CustomerName = Cust.CustomerName;
                        }
                        Boolean b = false;

                        foreach (var a in invoices)
                        {
                            if ((a.DateOfMonth == Invoices.DateOfMonthPay || a.DateOfMonthPay == Invoices.DateOfMonthPay) && a.CustomerID == Invoices.CustomerID)
                            {
                                if (Pay != null)
                                {
                                    a.PaymentCollection = Convert.ToInt32(Pay.PaymentAmount) + a.PaymentCollection;
                                }
                                b = true;
                            }
                        }
                        if (b == false)
                        {
                            if (Pay != null)
                            {
                                Invoices.PaymentCollection = Convert.ToInt32(Pay.PaymentAmount);
                            }
                            invoices.Add(Invoices);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            invoices = invoices.OrderBy(e => e.DateOfMonth).ThenBy(e => e.CustomerName).ToList();
            return(invoices);
        }
Пример #7
0
 public CustomerDetailController(TestDetailContext testDetailContext)
 {
     _testDetailContext = testDetailContext;
 }
Пример #8
0
        public List <Dashboard> GetDashboards()
        {
            List <Dashboard> DashbordList = new List <Dashboard>();

            try
            {
                using (var db = new TestDetailContext())
                {
                    Dashboard dashboard = new Dashboard();
                    dashboard.TotalCustomer = db.CustomerTbl.Count();
                    dashboard.TotalInvoices = db.InvoiceTbl.Count();
                    dashboard.TotalPayments = db.PaymentTbl.Count();


                    DateTime time = DateTime.Today;

                    var Month = (time.Month);
                    var Year  = (time.Year);


                    //foreach (var inv in db.InvoiceTbl.ToList())
                    //{
                    //    dashboard.TotalSeles += Convert.ToInt32(inv.InvoiceAmount);
                    //}


                    //foreach (var Pay in db.PaymentTbl.ToList())
                    //{
                    //    dashboard.TotalPaymentCollestions += Convert.ToInt32(Pay.PaymentAmount);
                    //}
                    foreach (var ct in db.CustomerTbl.ToList())
                    {
                        if (ct.CreatedDate != null)
                        {
                            if (ct.CreatedDate.Year == Year)
                            {
                                dashboard.CustomerYearly += 1;

                                if (ct.CreatedDate.Month == Month)
                                {
                                    dashboard.CustomerMonthly += 1;
                                }
                            }
                        }
                    }

                    foreach (var inv in db.InvoiceTbl.ToList())
                    {
                        if (inv.InvoiceDate.Year == Year)
                        {
                            dashboard.SalesYearly   += Convert.ToInt32(inv.InvoiceAmount);
                            dashboard.InvoiceYearly += 1;
                            if (inv.InvoiceDate.Month == Month)
                            {
                                dashboard.SalesMonthly   += Convert.ToInt32(inv.InvoiceAmount);
                                dashboard.InvoiceMonthly += 1;
                            }
                        }
                        dashboard.TotalSeles += Convert.ToInt32(inv.InvoiceAmount);
                    }

                    foreach (var Pay in db.PaymentTbl.ToList())
                    {
                        if (Pay.PaymentDate.Year == Year)
                        {
                            dashboard.PaymentCollestionsYearly += Convert.ToInt32(Pay.PaymentAmount);
                            dashboard.PaymentsYearly           += 1;
                            if (Pay.PaymentDate.Month == Month)
                            {
                                dashboard.PaymentCollestionsMonthly += Convert.ToInt32(Pay.PaymentAmount);
                                dashboard.PaymentsMonthly           += 1;
                            }
                        }

                        dashboard.TotalPaymentCollestions += Convert.ToInt32(Pay.PaymentAmount);
                    }
                    if ((dashboard.TotalCustomer - dashboard.CustomerMonthly) != 0)
                    {
                        dashboard.CustomerMonthlyGrowth = (dashboard.CustomerMonthly / (dashboard.TotalCustomer - dashboard.CustomerMonthly)) * 100;
                    }
                    else
                    {
                        dashboard.CustomerMonthlyGrowth = 100;
                    }

                    if ((dashboard.TotalCustomer - dashboard.CustomerYearly) != 0)
                    {
                        dashboard.CustomerYearlyGrowth = (dashboard.CustomerYearly / (dashboard.TotalCustomer - dashboard.CustomerYearly)) * 100;
                    }
                    else
                    {
                        dashboard.CustomerYearlyGrowth = 100;
                    }

                    if ((dashboard.TotalSeles - dashboard.SalesMonthly) != 0)
                    {
                        dashboard.SalesMonthlyGrowth = Convert.ToInt32((dashboard.SalesMonthly / (dashboard.TotalSeles - dashboard.SalesMonthly)) * 100);
                    }
                    else
                    {
                        dashboard.SalesMonthlyGrowth = 100;
                    }

                    if ((dashboard.TotalSeles - dashboard.SalesYearly) != 0)
                    {
                        dashboard.SalesYearlyGrowth = Convert.ToInt32((dashboard.SalesYearly / (dashboard.TotalSeles - dashboard.SalesYearly)) * 100);
                    }
                    else
                    {
                        dashboard.SalesYearlyGrowth = 100;
                    }

                    if ((dashboard.TotalPaymentCollestions - dashboard.PaymentCollestionsMonthly) != 0)
                    {
                        dashboard.PaymentCollestionsMonthlyGroth = Convert.ToInt32((dashboard.PaymentCollestionsMonthly / (dashboard.TotalPaymentCollestions - dashboard.PaymentCollestionsMonthly)) * 100);
                    }
                    else
                    {
                        dashboard.PaymentCollestionsMonthlyGroth = 100;
                    }

                    if ((dashboard.TotalPaymentCollestions - dashboard.PaymentCollestionsYearly) != 0)
                    {
                        dashboard.PaymentCollestionsYearlyGrowth = Convert.ToInt32((dashboard.PaymentCollestionsYearly / (dashboard.TotalPaymentCollestions - dashboard.PaymentCollestionsYearly)) * 100);
                    }
                    else
                    {
                        dashboard.PaymentCollestionsYearlyGrowth = 100;
                    }

                    DashbordList.Add(dashboard);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(DashbordList);
        }