Example #1
0
        public async Task <IActionResult> Approve(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var allowance = await _context.Allowance
                            .Include(a => a.AllowanceType).Include(e => e.CreatedBy).Include(e => e.AssignedCategory)
                            .FirstOrDefaultAsync(m => m.AllowanceID == id);

            if (allowance == null)
            {
                return(NotFound());
            }
            allowance.ApprovedStatus = ApprovedStatus.APPROVED;
            _context.Allowance.Update(allowance);
            _context.SaveChanges();
            await Task.Run(() => SendMail(allowance));

            if (_viewModel.IsFromFilter)
            {
                return(await Filter(_viewModel));
            }
            return(RedirectToAction(nameof(Index)));
        }
Example #2
0
 public IViewComponentResult Invoke(RosterViewModel model)
 {
     model.Rosters.Clear();
     foreach (ApplicationUser user in model.AllUsers)
     {
         List <Roster> roster = context.Rosters.Include(e => e.RosterShift).Where(e => e.UserId == user.Id && e.Date.Month == model.Month.Month).ToList();
         if (roster.Count <= 0)
         {
             foreach (var date in model.Dates)
             {
                 var regularShift = model.RosterShifts.Where(e => e.RosterShiftName == Constants.R).FirstOrDefault();
                 if (date.DayOfWeek.ToString() == Constants.SATURDAY || date.DayOfWeek.ToString() == Constants.SUNDAY)
                 {
                     regularShift = model.RosterShifts.Where(e => e.RosterShiftName == Constants.OFF).FirstOrDefault();
                 }
                 context.Rosters.Add(new Roster
                 {
                     Date        = date,
                     CreatedOn   = DateTime.Now,
                     IsActive    = true,
                     IsSelected  = false,
                     User        = user,
                     RosterShift = user.IsRegularShift ? regularShift : null
                 });
             }
             context.SaveChanges();
             model.Rosters.AddRange(context.Rosters.Include(e => e.RosterShift).Where(e => e.UserId == user.Id && e.Date.Month == DateTime.Now.Month).ToList());
         }
         else
         {
             model.Rosters.AddRange(roster);
         }
     }
     return(View(model));
 }
Example #3
0
 public ActionResult EmailConfirm(string id)
 {
     if (id != null)
     {
         var user = userManager.FindByIdAsync(id).Result;
         user.EmailConfirmed = true;
         _context.User.Update(user);
         _context.SaveChanges();
     }
     return(RedirectToAction(nameof(Index)));
 }
Example #4
0
        public static void Initialize(CygateWMSContext context)
        {
            context.Database.EnsureCreated(); //if it(your database) doesn't exist ,it will be created
            context.Database.Migrate();

            //Roles
            if (!context.Roles.Any())
            {
                context.Roles.Add(new ApplicationRole()
                {
                    Name = Constants.ADMIN, NormalizedName = Constants.ADMIN, CreatedDate = DateTime.Now, IsActive = true, Description = "Admin"
                });
                context.Roles.Add(new ApplicationRole()
                {
                    Name = Constants.USER, NormalizedName = Constants.USER, CreatedDate = DateTime.Now, IsActive = true, Description = "User"
                });
                context.Roles.Add(new ApplicationRole()
                {
                    Name = Constants.TL, NormalizedName = Constants.TL, CreatedDate = DateTime.Now, IsActive = true, Description = "Team Leader"
                });
                context.SaveChanges();
            }
            //Category
            if (!context.Category.Any())
            {
                context.Category.Add(new Category()
                {
                    CategoryName = Constants.LINUX, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Category.Add(new Category()
                {
                    CategoryName = Constants.WINDOWS, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Category.Add(new Category()
                {
                    CategoryName = Constants.VMWARE, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Category.Add(new Category()
                {
                    CategoryName = Constants.NETWORKING, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Category.Add(new Category()
                {
                    CategoryName = Constants.ADMIN, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Category.Add(new Category()
                {
                    CategoryName = Constants.PROCUREMENT, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Category.Add(new Category()
                {
                    CategoryName = Constants.DEVELOPMENT, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Category.Add(new Category()
                {
                    CategoryName = Constants.FINANCE, CreatedOn = DateTime.Now, IsActive = true
                });
                context.SaveChanges();
            }
            //Type
            if (!context.Type.Any())
            {
                context.Type.Add(new Models.Type()
                {
                    TypeName = Constants.ALERT, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Type.Add(new Models.Type()
                {
                    TypeName = Constants.CHAT, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Type.Add(new Models.Type()
                {
                    TypeName = Constants.DOCUMENTATION, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Type.Add(new Models.Type()
                {
                    TypeName = Constants.INCIDENT, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Type.Add(new Models.Type()
                {
                    TypeName = Constants.PHREPORT, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Type.Add(new Models.Type()
                {
                    TypeName = Constants.PROJECTS, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Type.Add(new Models.Type()
                {
                    TypeName = Constants.SCHEDULEDTASK, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Type.Add(new Models.Type()
                {
                    TypeName = Constants.TASK, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Type.Add(new Models.Type()
                {
                    TypeName = Constants.TICKET, CreatedOn = DateTime.Now, IsActive = true
                });
                context.SaveChanges();
            }
            //Shift
            if (!context.Shift.Any())
            {
                context.Shift.Add(new Shift()
                {
                    ShiftName = Constants.GENERAL, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Shift.Add(new Shift()
                {
                    ShiftName = Constants.SHIFT_A, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Shift.Add(new Shift()
                {
                    ShiftName = Constants.SHIFT_B, CreatedOn = DateTime.Now, IsActive = true
                });
                context.Shift.Add(new Shift()
                {
                    ShiftName = Constants.SHIFT_C, CreatedOn = DateTime.Now, IsActive = true
                });
                context.SaveChanges();
            }
            //onCallEscalates
            if (!context.onCallEscalates.Any())
            {
                context.onCallEscalates.Add(new OnCallEscalate()
                {
                    OnCallEscalateName = Constants.NO, CreatedOn = DateTime.Now, IsActive = true
                });
                context.onCallEscalates.Add(new OnCallEscalate()
                {
                    OnCallEscalateName = Constants.YES_INDIA, CreatedOn = DateTime.Now, IsActive = true
                });
                context.onCallEscalates.Add(new OnCallEscalate()
                {
                    OnCallEscalateName = Constants.YES_SWEDEN, CreatedOn = DateTime.Now, IsActive = true
                });
                context.SaveChanges();
            }
            //onCallEscalates
            if (!context.AllowanceType.Any())
            {
                context.AllowanceType.Add(new AllowanceType()
                {
                    AllowanceTypeName = Constants.HOLIDAY, AllowanceTypePrice = 1250, CreatedOn = DateTime.Now, IsActive = true
                });
                context.AllowanceType.Add(new AllowanceType()
                {
                    AllowanceTypeName = Constants.NIGHT, AllowanceTypePrice = 400, CreatedOn = DateTime.Now, IsActive = true
                });
                context.SaveChanges();
            }
            //ShiftRoster
            if (!context.RosterShifts.Any())
            {
                context.RosterShifts.Add(new RosterShift()
                {
                    RosterShiftName = Constants.A, CreatedOn = DateTime.Now, IsActive = true
                });
                context.RosterShifts.Add(new RosterShift()
                {
                    RosterShiftName = Constants.B, CreatedOn = DateTime.Now, IsActive = true
                });
                context.RosterShifts.Add(new RosterShift()
                {
                    RosterShiftName = Constants.C, CreatedOn = DateTime.Now, IsActive = true
                });
                context.RosterShifts.Add(new RosterShift()
                {
                    RosterShiftName = Constants.R, CreatedOn = DateTime.Now, IsActive = true
                });
                context.RosterShifts.Add(new RosterShift()
                {
                    RosterShiftName = Constants.OFF, CreatedOn = DateTime.Now, IsActive = true
                });
                context.RosterShifts.Add(new RosterShift()
                {
                    RosterShiftName = Constants.PL, CreatedOn = DateTime.Now, IsActive = true
                });
                context.RosterShifts.Add(new RosterShift()
                {
                    RosterShiftName = Constants.CL, CreatedOn = DateTime.Now, IsActive = true
                });
                context.RosterShifts.Add(new RosterShift()
                {
                    RosterShiftName = Constants.SL, CreatedOn = DateTime.Now, IsActive = true
                });
                context.SaveChanges();
            }
        }
Example #5
0
        public async Task <RosterViewModel> GetIndexRosterViewModel(DateTime Year, DateTime Month)
        {
            RosterViewModel rosterViewModel = new RosterViewModel();

            rosterViewModel.Month = Month;
            var currentUser = await userManager.GetUserAsync(HttpContext.User);

            rosterViewModel.AllUsers = userManager.Users.ToList();
            List <Holiday> holidays = await context.Holiday.Where(e => e.IsActive == true && e.Year == DateTime.Now.Year).ToListAsync();

            rosterViewModel.Dates = GetDates(Year.Year, Month.Month);

            rosterViewModel.RosterShifts = context.RosterShifts.Where(e => e.IsActive).ToList();
            rosterViewModel.Categories   = context.Category.Where(e => e.CategoryName != Constants.ADMIN && e.IsActive).ToList();
            if (User.IsInRole(Constants.TL))
            {
                rosterViewModel.Users = userManager.Users.Where(e => e.CategoryId == currentUser.CategoryId && e.Id != currentUser.Id).ToList();
            }
            else if (User.IsInRole(Constants.ADMIN))
            {
                rosterViewModel.Users = userManager.Users.Where(e => !e.IsRegularShift).ToList();
            }
            else
            {
                rosterViewModel.Users = userManager.Users.Where(e => e.Id == currentUser.Id).ToList();
            }

            foreach (ApplicationUser user in rosterViewModel.Users)
            {
                List <Roster> roster = context.Rosters.Include(e => e.RosterShift).Where(e => e.UserId == user.Id && e.Date.Month == Month.Month).ToList();
                if (roster.Count <= 0)
                {
                    foreach (var date in rosterViewModel.Dates)
                    {
                        var regularShift = rosterViewModel.RosterShifts.Where(e => e.RosterShiftName == Constants.R).FirstOrDefault();
                        if ((date.DayOfWeek.ToString() == Constants.SATURDAY || date.DayOfWeek.ToString() == Constants.SUNDAY) && user.IsRegularShift == true)
                        {
                            regularShift = rosterViewModel.RosterShifts.Where(e => e.RosterShiftName == Constants.OFF).FirstOrDefault();
                        }
                        Holiday holiday = holidays.Find(e => e.Date == date);
                        if (holiday != null && user.IsRegularShift == true)
                        {
                            context.Rosters.Add(new Roster
                            {
                                Date        = date,
                                CreatedOn   = DateTime.Now,
                                IsActive    = true,
                                IsSelected  = false,
                                User        = user,
                                RosterShift = rosterViewModel.RosterShifts.Where(e => e.RosterShiftName == Constants.OFF).FirstOrDefault()
                            });
                        }
                        else
                        {
                            context.Rosters.Add(new Roster
                            {
                                Date        = date,
                                CreatedOn   = DateTime.Now,
                                IsActive    = true,
                                IsSelected  = false,
                                User        = user,
                                RosterShift = user.IsRegularShift ? regularShift : null
                            });
                        }
                    }
                    context.SaveChanges();
                    roster = context.Rosters.Include(e => e.RosterShift).Where(e => e.UserId == user.Id && e.Date.Month == Month.Month).ToList();
                    roster.ForEach(item =>
                    {
                        item.RosterShifts = rosterViewModel.RosterShifts.Select(e => new SelectListItem
                        {
                            Text     = e.RosterShiftName,
                            Value    = e.RosterShiftId.ToString(),
                            Selected = item.RosterShift != null ? (item.RosterShift.RosterShiftId == e.RosterShiftId ? true : false) : false
                        }).ToList();
                        item.RosterShifts.Add(new SelectListItem {
                            Text = "NA", Value = string.Empty, Selected = string.IsNullOrEmpty(item.RosterShift?.RosterShiftId.ToString()) ? true : false
                        });
                    });
                    rosterViewModel.Rosters.AddRange(roster);
                }
                else
                {
                    roster.ForEach(item =>
                    {
                        item.RosterShifts = rosterViewModel.RosterShifts.Select(e => new SelectListItem
                        {
                            Text     = e.RosterShiftName,
                            Value    = e.RosterShiftId.ToString(),
                            Selected = item.RosterShift != null ? (item.RosterShift.RosterShiftId == e.RosterShiftId ? true : false) : false
                        }).ToList();
                        item.RosterShifts.Add(new SelectListItem {
                            Text = "NA", Value = string.Empty, Selected = string.IsNullOrEmpty(item.RosterShift?.RosterShiftId.ToString()) ? true : false
                        });
                    });
                    rosterViewModel.Rosters.AddRange(roster);
                }
            }
            await Task.Run(async() => { await GetRosterViewModel(Year, Month); });

            return(rosterViewModel);
        }