Beispiel #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new v3xContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <v3xContext> >()))
            {
                // Look for any movies.
                if (context.People.Any())
                {
                    return;   // DB has been seeded
                }

                context.People.AddRange(
                    new People
                {
                    Name        = "Lee Keen Shen",
                    Password    = "******",
                    Email       = "*****@*****.**",
                    Role        = "superadmin",
                    Tel         = "016-5654444",
                    Nationality = "Malaysian",
                    DateOfBirth = "01/02/1950",
                    Address     = "Ipoh Perak"
                },
                    new People
                {
                    Name        = "CS",
                    Password    = "******",
                    Email       = "*****@*****.**",
                    Role        = "admin",
                    Tel         = "016-999999",
                    Nationality = "Malaysian",
                    DateOfBirth = "31/02/2030",
                    Address     = "Penang"
                },
                    new People
                {
                    Name        = "yen ping",
                    Password    = "******",
                    Email       = "*****@*****.**",
                    Role        = "employee",
                    Tel         = "016-111111",
                    Nationality = "Malaysian",
                    DateOfBirth = "01/02/1888",
                    Address     = "Johor Tebrau"
                }


                    );
                context.SaveChanges();
            }
        }
        public IActionResult PaySave(List <v3x.Models.PaySlip> model)
        {
            if (HttpContext.Session.GetString("Session_Role") == veryrole)
            {
                var existDates = _context.PaySlip.Select(d => d.Date.ToString("MMMM yyyy")).Distinct().ToList();
                var anyDate    = model.FirstOrDefault().Date.ToString("MMMM yyyy");

                if (existDates.Where(x => x == anyDate).FirstOrDefault() != null)
                {
                    // redirect
                    return(RedirectToAction(nameof(Index)));
                }

                foreach (var payslip in model)
                {
                    _context.Add(payslip);
                    _context.SaveChanges();
                }

                //IDictionary<int, List<string>> dict = new Dictionary<int, List<string>>();
                //var JobId =  _context.Job.Select(j => j.JobId).ToList();
                //int yes = 0;
                //foreach (var item in model)
                //{
                //    item.Job = _context.Job.Where(x => x.JobId == item.JobId).Include(y => y.People).FirstOrDefault();
                //    var verifydate = item.Date.ToString("MMMM yyyy");
                //    foreach (var c in JobId)
                //    {
                //        if(item.JobId == c)
                //        {
                //            var getdate = _context.PaySlip.Where(x => x.JobId == c).Select(j => j.Date.ToString("MMMM yyyy")).ToList();
                //            foreach(var d in getdate)
                //            {
                //                if(verifydate == d)
                //                {
                //                    yes = 1;
                //                }
                //                else
                //                {
                //                    yes = 0;
                //                }
                //                if(yes == 1)
                //                {
                //                    return RedirectToAction(nameof(Index));
                //                }

                //            }
                //        }

                //    }

                //    _context.Add(item);
                //    _context.SaveChanges();
                //}

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }