public void UnrestrictOrganization(int roleId, int organizationId)
        {
            Role            role            = this.tdb.Roles.Single(y => y.Id == roleId);
            Organization    org             = this.tdb.Organizations.Single(y => y.Id == organizationId);
            RoleRestriction roleRestriction = role.Restrictions.Single(y => y.Organization == org);

            this.tdb.RoleRestrictions.DeleteObject(roleRestriction);

            this.tdb.SaveChanges();
        }
        public void RestrictOrganizations(int roleId, int organizationId)
        {
            Role         role = this.tdb.Roles.Single(y => y.Id == roleId);
            Organization org  = this.tdb.Organizations.Single(y => y.Id == organizationId);

            if (role.Restrictions.Count(y => y.Organization == org) > 0)
            {
                return;
            }

            RoleRestriction newRoleRestriction = new RoleRestriction();

            newRoleRestriction.Role         = role;
            newRoleRestriction.Organization = org;
            this.tdb.RoleRestrictions.AddObject(newRoleRestriction);

            this.tdb.SaveChanges();
        }
        public JsonResult AddNewEventAJAX(string name, string date, string timeHour, string timeMin, string timeMeridian, string typeID, int charID, int roleID, 
                                          string meetupLocation, string notes, string inHealRestriction, string inTankRestriction, string inDamageRestriction)
        {
            List<string> errors = new List<string>();
            DateTime evtDate = new DateTime();
            if (!DateTime.TryParse(date, out evtDate)) { errors.Add(Errors.DATE_INVALID); }
            //Validate that charID is for a character that belongs to the current member
            MemCharacter creatorCharacter = charInterface.GetCharacterByID(charID);
            if (creatorCharacter == null) { errors.Add(Errors.CHARACTER_NOT_FOUND); }
            //Validate Time
            TimeSpan eventTime = new TimeSpan();
            string time = DataAccessLayer.Global.Global.ConvertMeridianTimeTo24Hour(timeHour, timeMin, timeMeridian);
            //if (!System.Text.RegularExpressions.Regex.IsMatch(time, @"[0-23]:[0-59]")) { errors.Add(Errors.TIME_INVALID); }
            if (!TimeSpan.TryParse(time, out eventTime)) { errors.Add(Errors.TIME_INVALID); }

            //Validate Role Restrictions
            string healerRestrictionInput = (!String.IsNullOrEmpty(inHealRestriction)) ? inHealRestriction : "0";
            string tankRestrictionInput = (!String.IsNullOrEmpty(inTankRestriction)) ? inTankRestriction : "0";
            string damageRestrictionInput = (!String.IsNullOrEmpty(inDamageRestriction)) ? inDamageRestriction : "0";

            int healerRestriction = 0;
            if(!Int32.TryParse(healerRestrictionInput, out healerRestriction))
            {
                errors.Add("Issue with Healer Restriction");
            }
            int tankRestriction = 0;
            if (!Int32.TryParse(tankRestrictionInput, out tankRestriction))
            {
                errors.Add("Issue with Tank Restriction");
            }
            int damageRestriction = 0;
            if (!Int32.TryParse(damageRestrictionInput, out damageRestriction))
            {
                errors.Add("Issue with Damage Restriction");
            }

            //Need to handle event time better. If I wanted to make an hourly calendar how would that work
            bool success = false;
            if (errors.Count == 0)
            {
                //Add new Event
                Event evt = new Event()
                {
                    Date = evtDate,
                    EventCreaterMemberID = MemberInfo.MemberID,
                    EventName = name,
                    //EventRestrictionsID = null,
                    EventTime = eventTime,
                    EventTypeID = Convert.ToInt32(typeID),
                    MeetupLocation = meetupLocation,
                    Notes = notes,
                    GameID = creatorCharacter.GameID,
                    Active = true,
                    ServerID = (int)creatorCharacter.ServerID

                };
                success = eventInterface.AddNewEvent(evt);

                //If there is a serverID or a factionID go ahead and setup a basic restriction
                if (evt.ServerID != null || creatorCharacter.FactionID != null)
                {
                    eventInterface.AddBasicRestrictions(evt.EventID, evt.ServerID, creatorCharacter.FactionID);
                }

                //Add Event Restrictions
                RoleRestriction[] roleRestrictions = new RoleRestriction[] {
                    new RoleRestriction() { RoleID = 1, Quantity = damageRestriction},
                      new RoleRestriction() {RoleID = 2, Quantity = healerRestriction},
                      new RoleRestriction() {RoleID = 3, Quantity = tankRestriction}
                    };
                eventInterface.InsertRoleRestrictions(evt.EventID, roleRestrictions);

                //Creator is automatically added to the raid attendees
                CommitResponse autoMemberAddSuccess  = eventInterface.AddNewEventAttendee(charID, evt.EventID, roleID, String.Empty, (int)ATTENDEE_STATUS.ACCEPTED, MemberInfo.MemberID);
            }
            else
            {
                //There was an issue with input
            }

            //Success Response
            return new JsonResult() { Data = success };
        }
        public ActionResult Edit(Event evt)
        {
            int charID = Convert.ToInt32(Request["Char"]);
            MemCharacter creatorCharacter = charInterface.GetCharacterByID(charID);

            //Add in sensetive data
            evt.EventID = CurrentEvent.EventID;
            evt.GameID = CurrentEvent.GameID;
            evt.EventTypeID = (evt.EventTypeID != 0) ? evt.EventTypeID : CurrentEvent.EventTypeID;
            evt.EventCreaterMemberID = CurrentEvent.EventCreaterMemberID;
            evt.ServerID = creatorCharacter.ServerID;

            string note = (!String.IsNullOrEmpty(Request["Note"])) ? Request["Note"] : String.Empty;
            int roleID =  (!String.IsNullOrEmpty(Request["RoleID"])) ? Convert.ToInt32(Request["RoleID"]) : 0;

            //Add in Role Restriction Data
            string healerRestrictionInput = (!String.IsNullOrEmpty(Request["HealerRestriction"])) ? Request["HealerRestriction"] : "0";
            string tankRestrictionInput = (!String.IsNullOrEmpty(Request["TankRestriction"])) ? Request["TankRestriction"] : "0";
            string damageRestrictionInput = (!String.IsNullOrEmpty(Request["DamageRestriction"])) ? Request["DamageRestriction"] : "0";
            int healerRestriction = 0;
            if (!Int32.TryParse(healerRestrictionInput, out healerRestriction))
            {
                //errors.Add("Issue with Healer Restriction");
            }
            int tankRestriction = 0;
            if (!Int32.TryParse(tankRestrictionInput, out tankRestriction))
            {
                //errors.Add("Issue with Tank Restriction");
            }
            int damageRestriction = 0;
            if (!Int32.TryParse(damageRestrictionInput, out damageRestriction))
            {
                //errors.Add("Issue with Damage Restriction");
            }

            bool success = eventInterface.EditEvent(evt);
            if (success)
            {
                eventInterface.UpdateAttendeeStatus(CurrentEvent.EventID, MemberInfo.MemberID, (int)ATTENDEE_STATUS.ACCEPTED, charID , note, roleID);

                //Updatee Restrictions
                    RoleRestriction[] roleRestrictions = new RoleRestriction[] {
                        new RoleRestriction() { RoleID = 1, Quantity = damageRestriction},
                        new RoleRestriction() {RoleID = 2, Quantity = healerRestriction},
                        new RoleRestriction() {RoleID = 3, Quantity = tankRestriction}
                    };
                eventInterface.UpdateRestrictions(CurrentEvent.EventID, roleRestrictions, evt.ServerID, creatorCharacter.FactionID);
                //eventInterface.UpdateRoleRestrictions(CurrentEvent.EventID, roleRestrictions);

                return RedirectToAction("Index");
            }
            else
            {
                ModelState.AddModelError("Error", "Couldnt edit this event");
                return View();
            }
        }