Beispiel #1
0
        // Add/Remove Staff Hours to EventStaff Table
        public IActionResult AddOrRemoveHours(int Hours, int EventID, int StaffID)
        {
            Event newEvent =
                context.Events.Single(e => e.ID == EventID);
            Staff newStaff =
                context.Staffs.Single(s => s.ID == StaffID);
            //Pull specific EventStaff Object to add/remove hours
            EventStaff eventStaff = context.EventStaffs.Single(es => es.EventID == EventID && es.StaffID == StaffID);

            if (Hours > 0)
            {
                newEvent.TotalCost += newStaff.Wage * Hours;
                eventStaff.Hours   += Hours;
            }
            else if (Hours < 0)
            {
                Hours *= -1;
                //if Hours to remove is more then eventStaff.Hours then set Hours to equal eventStaff.Hours
                if (Hours > eventStaff.Hours)
                {
                    Hours = eventStaff.Hours;
                }
                newEvent.TotalCost -= newStaff.Wage * Hours;
                eventStaff.Hours   -= Hours;
            }
            context.SaveChanges();
            return(Redirect("/Event/ViewEvent/" + EventID));
        }
Beispiel #2
0
        //Create a relationship between current Event and an Staff.
        public IActionResult AddStaff(ViewEventViewModel viewEventViewModel, int EventID)
        {
            if (ModelState.IsValid)
            {
                //if a relationship already exists between an Event object and Staff object it adds EventStaff
                //object to list.
                IList <EventStaff> existingItems = context.EventStaffs
                                                   .Where(es => es.EventID == EventID)
                                                   .Where(es => es.StaffID == viewEventViewModel.StaffID).ToList();
                if (!existingItems.Any())
                {
                    //EventStaff Constructor
                    EventStaff eventStaff = new EventStaff
                    {
                        StaffID = viewEventViewModel.StaffID,

                        EventID = EventID
                    };

                    context.EventStaffs.Add(eventStaff);
                    context.SaveChanges();
                }
            }
            return(Redirect("/Event/ViewEvent/" + EventID));
        }
        public async Task <IActionResult> AddStaff(int?Id, int StaffId)
        {
            if (!Id.HasValue)
            {
                return(NotFound());
            }

            var existCheck = await _context.EventStaff.FindAsync(StaffId, Id);

            if (existCheck != null)
            {
                return(BadRequest());
            }

            EventStaff staff = new EventStaff()
            {
                EventId = Id.Value,
                StaffId = StaffId
            };

            await _context.EventStaff.AddAsync(staff);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Staff), new { id = Id.Value }));
        }
Beispiel #4
0
        public string RegisterStaff(EventStaff _staff)
        {
            HashPass hashedPass = new HashPass();
            string   pass       = HashPass.HashPassword(_staff.PASS);

            using (EventrixDBDataContext dbd = new EventrixDBDataContext())
            {
                try
                {
                    int MailChecker = (from eh in dbd.Staffs where eh.Email.Equals(_staff.EMAIL) && eh.eventid == _staff.EventID select eh).Count();
                    if (MailChecker == 0)
                    {
                        int   _id   = Convert.ToInt32(_staff.EventID);
                        Staff staff = new Staff();
                        staff.Name       = _staff.NAME;
                        staff.Email      = _staff.EMAIL;
                        staff.Occupation = _staff.Occupation;
                        staff.Password   = pass;
                        staff.eventid    = _id;
                        dbd.Staffs.InsertOnSubmit(staff);
                        dbd.SubmitChanges();
                        return("Registered " + staff.Name + " successfully");
                    }
                    else
                    {
                        return("Error: Account already taken");
                    }
                }
                catch (Exception e)
                {
                    return(e.GetBaseException().ToString());
                }
            };
        }
Beispiel #5
0
        public bool deleteStaff(EventStaff _staff)
        {
            int _id = Convert.ToInt32(_staff.EventID);

            try
            {
                using (EventrixDBDataContext db = new EventrixDBDataContext())
                {
                    List <Staff> toDelete = (from dl in db.Staffs where dl.eventid == _id select dl).ToList();
                    if (toDelete == null)
                    {
                        return(false);
                    }
                    else
                    {
                        db.Staffs.DeleteAllOnSubmit(toDelete);
                        db.SubmitChanges();
                        return(true);
                    }
                };
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #6
0
        //Using the list of ids remove Staff from Event for each id in objIds.
        public IActionResult RemoveStaff(int[] objIds, int id)
        {
            Event newEvent =
                context.Events.Single(e => e.ID == id);

            foreach (int staffId in objIds)
            {
                EventStaff theEventStaff = context.EventStaffs
                                           .Single(es => es.EventID == id && es.StaffID == staffId);
                Staff newStaff =
                    context.Staffs.Single(s => s.ID == staffId);
                newEvent.TotalCost -= theEventStaff.Hours * newStaff.Wage;

                context.EventStaffs.Remove(theEventStaff);
            }

            context.SaveChanges();

            return(Redirect("/Event/ViewEvent/" + id));
        }
Beispiel #7
0
 public EventStaff updateSTaff(string id, EventStaff _event)
 {
     using (EventrixDBDataContext db = new EventrixDBDataContext())
     {
         try
         {
             var query = (from add in db.Staffs where add.Email.Equals(_event.EMAIL) select add);
             if (query.Count() == 1)
             {
                 Staff res = query.Single();
                 //  res.StaffId = _event.ID;
                 res.Name       = _event.NAME;
                 res.Occupation = _event.Occupation;
                 // res.Email = _event.EMAIL;
                 res.Password = _event.PASS;
                 //  res.eventid = _event.EventID;
                 db.SubmitChanges();
                 _event = new EventStaff()
                 {
                     ID         = res.StaffId,
                     NAME       = res.Name,
                     Occupation = res.Occupation,
                     EMAIL      = res.Email,
                     PASS       = res.Password,
                     EventID    = res.eventid,
                 };
                 return(_event);
             }
             else
             {
                 return(null);
             }
         }
         catch (Exception)
         {
             return(null);
         }
     }
 }