Ejemplo n.º 1
0
        public static void SeedClubs(RosterContext context)
        {
            Club lsc = new Club
            {
                Name         = "Langstone Sailing Club",
                ContactEmail = "*****@*****.**",
                PhoneNumber  = "07710471444"
            };
            Address lscAddress = new Address
            {
                Club        = lsc,
                HouseNumber = "LSC",
                Street      = "Langstone Rd",
                TownCity    = "Havant",
                Postcode    = "PO9 1RD"
            };

            lsc.Address.ToList().Add(lscAddress);
            if (!context.Clubs.Any(c => c.Name == lsc.Name))
            {
                context.Addresses.Add(lscAddress);
                context.Clubs.Add(lsc);
                context.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public JsonResult GetDuties(string start, string end)
        {
            DateTime startDate = Convert.ToDateTime(start);
            DateTime endDate   = Convert.ToDateTime(end);

            using (var context = RosterContext.Create())
            {
                var duties             = context.Duties.Where(d => d.FromDate >= startDate && d.ToDate <= endDate);
                List <DutyModel> model = new List <DutyModel>();
                foreach (var d in duties)
                {
                    model.Add(new DutyModel {
                        Id              = d.Id,
                        ClubId          = d.ClubId,
                        Description     = d.Description,
                        start           = d.FromDate.ToString("yyyy'-'MM'-'dd"),
                        end             = d.ToDate.ToString("yyyy'-'MM'-'dd"),
                        title           = d.Name,
                        Instructions    = d.Instructions,
                        UserId          = d.UserId,
                        starttime       = d.Starttime,
                        endtime         = d.Endtime,
                        backgroundColor = string.IsNullOrEmpty(d.UserId) ? "Red" : "Green"
                    });
                }
                return(Json(model, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a database session for connecting to the database
        /// </summary>
        /// <param name="container"></param>
        public static DbContext InitiateDataContext(IUnityContainer container)
        {
            var dbSession = new RosterContext(DatabaseName);

            dbSession.Configuration.EnsureTransactionsForFunctionsAndCommands = false;
            dbSession.Database.Log = (msg) => Logger.WriteLine(msg);
            return(dbSession);
        }
Ejemplo n.º 4
0
        // GET: SystemAdmin
        public ActionResult Index()
        {
            List <ClubModel> model = null;

            using (var context = new RosterContext())
            {
                model = context.Clubs.ProjectToList <ClubModel>();
            }
            return(View(model));
        }
Ejemplo n.º 5
0
 public bool Volunteer(int dutyId)
 {
     try
     {
         using (var context = RosterContext.Create())
         {
             var usr  = context.Users.First(u => u.Name == User.Identity.Name);
             var duty = context.Duties.First(d => d.Id == dutyId);
             duty.UserId = usr.Id;
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Default Constructor for dependency injection
 /// </summary>
 /// <param name="context"></param>
 public RosterService(DbContext context, bool strictMatching)
 {
     this.context        = context as RosterContext;
     this.strictMatching = strictMatching;
 }
Ejemplo n.º 7
0
 public Repository()
 {
     _context = new RosterContext();
 }
Ejemplo n.º 8
0
 public Repository(RosterContext context)
 {
     _context = context;
 }
Ejemplo n.º 9
0
        public static void SeedIdentities(RosterContext context)
        {
            //Create User Manager and Role Manager from the DB Part of the MVC Identity Framework
            var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

            //Check for and create roles if necessary
            if (!roleManager.RoleExists(RoleNames.SA))
            {
                var roleresult = roleManager.Create(new IdentityRole(RoleNames.SA));
            }
            if (!roleManager.RoleExists(RoleNames.ADMIN))
            {
                var roleresult = roleManager.Create(new IdentityRole(RoleNames.ADMIN));
            }
            if (!roleManager.RoleExists(RoleNames.USER))
            {
                var roleresult = roleManager.Create(new IdentityRole(RoleNames.USER));
            }
            //Check for and create SA user.
            string          sauser = "******";
            string          sapass = "******";
            ApplicationUser sa     = userManager.FindByName(sauser);

            if (sa == null)
            {
                sa = new ApplicationUser()
                {
                    Name                 = sauser,
                    UserName             = sauser,
                    Email                = sauser,
                    EmailConfirmed       = true,
                    PhoneNumber          = "07592517209",
                    PhoneNumberConfirmed = true,
                    ClubId               = 1
                };
                IdentityResult result = userManager.Create(sa, sapass);
                if (result.Succeeded)
                {
                    var roleResult = userManager.AddToRole(sa.Id, RoleNames.SA);
                }
            }
            //Check for and create ADMIN user.
            string          admuser = "******";
            string          admpass = "******";
            ApplicationUser admin   = userManager.FindByName(admuser);

            if (admin == null)
            {
                admin = new ApplicationUser()
                {
                    Name                 = admuser,
                    UserName             = admuser,
                    Email                = admuser,
                    EmailConfirmed       = true,
                    PhoneNumber          = "07592517209",
                    PhoneNumberConfirmed = true,
                    ClubId               = 1
                };
                IdentityResult result = userManager.Create(admin, admpass);
                if (result.Succeeded)
                {
                    var roleResult = userManager.AddToRole(admin.Id, RoleNames.ADMIN);
                }
            }
        }
Ejemplo n.º 10
0
        public static void SeedDuties(RosterContext context)
        {
            var SafteyBoatDriver = new DutyType
            {
                Name         = "Safety Boat Driver",
                ClubId       = 1,
                Description  = "Driving a safety boat for an event.",
                Instructions = "Provide adiquite safety coverage for the event."
                               // Sb driver ,SB assistant, Race officer ,RO assistant
            };
            var SafteyBoatAssistant = new DutyType
            {
                Name         = "Safety Boat Assistant",
                ClubId       = 1,
                Description  = "Assisting the safety boat driver.",
                Instructions = "Help driver provide adiquite safety coverage for the event."
            };
            var RaceOfficer = new DutyType
            {
                Name         = "Race Officer",
                ClubId       = 1,
                Description  = "Help running a race by conducting start sequence and finish times.",
                Instructions = "Help organise launching of participants and making apropriate choices for shortened course etc based on circumstances. "
            };
            var RaceOfficerassistant = new DutyType
            {
                Name         = "Race Officer Assistant",
                ClubId       = 1,
                Description  = "Assisting thhe Race officer in running a race.",
                Instructions = "Assist the race officer with their duties to the best of your ability."
            };
            var d1 = new Duty
            {
                Name        = "test1",
                ClubId      = 1,
                Description = "test SB driver",
                FromDate    = DateTime.Now.AddDays(3),
                ToDate      = DateTime.Now.AddDays(3.5),
                Starttime   = "9:00AM",
                Endtime     = "4:00PM"
            };
            var d2 = new Duty
            {
                Name        = "test2",
                ClubId      = 1,
                Description = "test SB Assistant",
                FromDate    = DateTime.Now.AddDays(3),
                ToDate      = DateTime.Now.AddDays(3.5),
                Starttime   = "9:00AM",
                Endtime     = "4:00PM"
            };
            var d3 = new Duty
            {
                Name        = "test3",
                ClubId      = 1,
                Description = "test Race Officer",
                FromDate    = DateTime.Now.AddDays(5),
                ToDate      = DateTime.Now.AddDays(5.5),
                Starttime   = "9:00AM",
                Endtime     = "4:00PM"
            };
            var d4 = new Duty
            {
                Name        = "test4",
                ClubId      = 1,
                Description = "test RO Assistant",
                FromDate    = DateTime.Now.AddDays(5),
                ToDate      = DateTime.Now.AddDays(5.5),
                Starttime   = "9:00AM",
                Endtime     = "4:00PM"
            };

            context.DutyTypes.Add(SafteyBoatDriver);
            context.DutyTypes.Add(SafteyBoatAssistant);
            context.DutyTypes.Add(RaceOfficer);
            context.DutyTypes.Add(RaceOfficerassistant);

            context.Duties.Add(d1);
            context.Duties.Add(d2);
            context.Duties.Add(d3);
            context.Duties.Add(d4);

            context.SaveChanges();
        }
Ejemplo n.º 11
0
 public RosterController(RosterContext context)
 {
     _context = context;
 }
Ejemplo n.º 12
0
        public JsonResult GetAvailStaffForShift(int id)
        {
            List <Staff> freeStaff = new List <Staff>();
            //shift conflict logic
            //get the required shift information from database associating to shiftId dropdown list
            var requiredShift = Repository.GetShiftById(id);

            if (requiredShift == null)
            {
                throw new NullReferenceException();
            }
            //get the required start and end time from corresponding shift
            var requiredStartTime = requiredShift.Start;
            var requiredEndTime   = requiredShift.End;
            //get all the corresponding staff from database associated to required role
            var staff = Repository.GetAvailStaffListForShift(id);

            //get database
            //join three tables: StaffShift/Shift/Staff
            using (var context = new RosterContext())
            {
                var StaffShiftTable = (from stf in context.Staff
                                       join ss in context.StaffShifts on stf.Id equals ss.StaffId
                                       join sft in context.Shifts on ss.ShiftId equals sft.Id
                                       orderby sft.End
                                       select new
                {
                    id = stf.Id,
                    name = stf.FirstName,
                    startTime = sft.Start,
                    endTime = sft.End
                }
                                       ).ToList();
                foreach (var person in staff)
                {
                    var StaffShiftTableById = StaffShiftTable.Where(s => s.id == person.Id).ToList();
                    //addable is the flag, if it is true, then we can add the current person to the dropdown list
                    bool addable = true;
                    foreach (var s in StaffShiftTableById)
                    {
                        //this is to check whether there is time conflict between required shift the all the shifts of the current staff
                        if (isTimeBetweenStartAndEndTime(s.startTime, s.endTime, requiredStartTime) ||
                            isTimeBetweenStartAndEndTime(s.startTime, s.endTime, requiredEndTime))
                        {
                            addable = false;
                            break;
                        }
                        //this is to check whether any shift of the current staff overlaps the required one
                        else if (requiredStartTime < s.startTime && requiredEndTime > s.endTime)
                        {
                            addable = false;
                            break;
                        }
                        // this is to check whether any shift of the current staff matches exactly the same as the required one
                        else if (requiredStartTime == s.startTime && requiredEndTime == s.endTime)
                        {
                            addable = false;
                            break;
                        }
                    }
                    if (addable)
                    {
                        // add this staff to result
                        freeStaff.Add(person);
                    }
                }
            }
            return(Json(new SelectList(freeStaff, "Id", "FirstName")));
        }