Пример #1
0
        public ActionResult AddGr(AddGroupsViewModel model, int?gid)
        {
            string          selU  = Request.Form["selUser"].ToString();
            ApplicationUser user  = db.Users.Where(u => u.Id == selU).Single();
            string          role  = Request.Form["roleSel"].ToString();
            Group           addGr = db.Groups.Where(g => g.GId == gid).Single();

            if (db.GroupPersons.Where(gg => gg.Group.GId == addGr.GId && gg.User.Id == user.Id).SingleOrDefault() != null)
            {
                return(RedirectToAction("AddGroupsParam", "Home", new { @gid = gid }));
            }

            GroupPerson gp = new GroupPerson();

            if (!db.GroupPersons.Any())
            {
                gp.Gpid = 1;
            }
            if (db.GroupPersons.Any())
            {
                gp.Gpid = db.GroupPersons.Max(grp => grp.Gpid) + 1;
            }
            gp.Group  = addGr;
            gp.User   = user;
            gp.Role   = role;
            gp.Status = "Invitation";
            user.Groups.Add(gp);
            addGr.Users.Add(gp);
            db.Users.Attach(user);
            db.Groups.Attach(addGr);
            db.GroupPersons.Add(gp);
            db.SaveChanges();
            return(RedirectToAction("GroupManagement", "Home", new { @gid = gid }));
        }
Пример #2
0
        public ActionResult DeleteGroupMember(int PersonNo, int GroupNo)
        {
            var         groupMembers        = unitOfWork.GroupPersonRepository.Find(x => x.GroupNo == GroupNo).AsEnumerable();
            var         groupMemberNo       = groupMembers.Where(x => x.GroupMemberPersonNo == PersonNo).FirstOrDefault().GroupMemberNo;
            GroupPerson GroupPersonToDelete = unitOfWork.GroupPersonRepository.FindBy(x => x.GroupMemberNo == groupMemberNo);

            unitOfWork.GroupPersonRepository.Remove(GroupPersonToDelete);
            unitOfWork.Save();
            return(ViewEditGroup(GroupNo, new GroupEdit()));
        }
Пример #3
0
 public IHttpActionResult AddPersonToGroup(int personid, int groupid)
 {
     try
     {
         Person      person = db.People.Where(x => x.PersonID == personid).FirstOrDefault();
         Group       group  = db.Groups.Where(x => x.GroupID == groupid).FirstOrDefault();
         GroupPerson gp     = new GroupPerson();
         gp.PersonId = person.PersonID;
         gp.GroupId  = group.GroupID;
         db.GroupPersons.Add(gp);
         db.SaveChanges();
         return(Ok(1));
     }
     catch
     {
         return(Ok(0));
     }
 }
Пример #4
0
        //public ActionResult CreateGroup(GroupEdit model)
        //{
        //    var grp = new Group()
        //    {
        //        GroupTypeNo = model.GroupType,
        //        GroupDesc = model.GroupDesc,
        //        StartDate = model.StartDate,
        //        EndDate = model.EndDate,
        //        SystemDate = DateTime.Now,
        //        GroupPersonNo = model.GroupPersonNo
        //    };
        //    unitOfWork.GroupRepository.Add(grp);
        //    unitOfWork.Save();
        //    ViewBag.Groups = ListOfGroups();
        //    return View("CreateGroup");
        //}

        public void AddGroupMember(int PersonNo, int GroupNo)
        {
            var grpMember = new GroupPerson()
            {
                GroupMemberPersonNo = PersonNo,
                GroupNo             = GroupNo,
                SystemDate          = DateTime.Now
            };
            var groups = unitOfWork.GroupPersonRepository.Find(x => x.GroupMemberPersonNo == PersonNo).AsEnumerable();
            var group  = groups.Where(x => x.GroupNo == GroupNo).FirstOrDefault();

            //var groupMember = unitOfWork.GroupPersonRepository.FindBy(x => x.GroupMemberPersonNo == PersonNo);
            if (group == null)
            {
                unitOfWork.GroupPersonRepository.Add(grpMember);
            }
            unitOfWork.Save();
        }
Пример #5
0
 protected Person(string name, bool isDriver, GroupPerson groupPerson)
 {
     Name        = name;
     IsDriver    = isDriver;
     GroupPerson = groupPerson;
 }
Пример #6
0
 public Cop(string name, bool isDriver = true, GroupPerson groupPerson = GroupPerson.Passenger) : base(name, isDriver, groupPerson)
 {
 }
Пример #7
0
 public Boss(string name, bool isDriver = true, GroupPerson groupPerson = GroupPerson.Cabin)
     : base(name, isDriver, groupPerson)
 {
 }
Пример #8
0
        public ActionResult Cg(CreateGViewModel model)
        {
            if (db.Groups.Where(g => g.Name == model.NameOfGroup).SingleOrDefault() != null)
            {
                ModelState.AddModelError("Error", @"This name is already occupied please think of another one");
                return(View("CreateG", model));
            }

            Group nGroup = new Group();

            if (!db.Groups.Any())
            {
                nGroup.GId = 1;
            }
            else
            {
                nGroup.GId = db.Groups.Max(g => g.GId) + 1;
            }
            nGroup.Name        = model.NameOfGroup;
            nGroup.Description = model.Description;
            byte[] imageData = null;
            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase poImgFile = Request.Files["Avatar"];

                using (var binary = new BinaryReader(poImgFile.InputStream))
                {
                    imageData = binary.ReadBytes(poImgFile.ContentLength);
                }
            }
            nGroup.Avatar = imageData;
            db.Groups.Add(nGroup);
            var me = new GroupPerson();
            var us = User.Identity.GetUserId();

            me.User  = db.Users.Where(u => u.Id == us).Single();
            me.Group = nGroup;
            if (!db.GroupPersons.Any())
            {
                me.Gpid = 1;
            }
            if (db.GroupPersons.Any())
            {
                me.Gpid = db.GroupPersons.Max(grp => grp.Gpid) + 1;
            }
            me.Role   = "Group Leader";
            me.Status = "Confirmed";
            db.GroupPersons.Add(me);
            string selMA = Request.Form["MASel"].ToString();
            var    newma = db.Users.Where(u => u.Id == selMA).Single();
            var    ma    = new GroupPerson();

            ma.User   = newma;
            ma.Group  = nGroup;
            ma.Gpid   = me.Gpid + 1;
            ma.Role   = "Main Advisor";
            ma.Status = "Invitation";
            db.GroupPersons.Add(ma);
            db.SaveChanges();
            return(RedirectToAction("GroupManagement", "Home", new { @gid = nGroup.GId }));
        }
Пример #9
0
 public Official(string name, bool isDriver = false, GroupPerson groupPerson = GroupPerson.Technical)
     : base(name, isDriver, groupPerson)
 {
 }
Пример #10
0
 public Stewardess(string name, bool isDriver = false, GroupPerson groupPerson = GroupPerson.Cabin)
     : base(name, isDriver, groupPerson)
 {
 }
Пример #11
0
 public Pilot(string name, bool isDriver = true, GroupPerson groupPerson = GroupPerson.Technical)
     : base(name, isDriver, groupPerson)
 {
 }
Пример #12
0
 public Prisoner(string name, bool isDriver = false, GroupPerson groupPerson = GroupPerson.Passenger)
     : base(name, isDriver, groupPerson)
 {
 }