示例#1
0
        public ActionResult Add(string name, string description)
        {
            try
            {
                var category = new CategoryMember();

                category.Name        = name;
                category.Description = description;

                _categoryMemberService.Insert(category);
                _categoryMemberService.SaveChanges();

                return(Content("1"));
            }
            catch (Exception)
            {
                return(Content("0"));
            }
        }
示例#2
0
        public ActionResult Save(RegisterViewModel model)
        {
            LoadLanguage(model);

            model.Tournaments = Session.Query <Tournament>().ToList();
            model.CurrentClub = Session.Query <User>().FirstOrDefault(x => x.Id == SecurityManager.AuthenticatedUser.Id).Club;

            if (model.SelectedTournamentId != Guid.Empty)
            {
                model.SelectedTournament = Session.Query <Tournament>().FirstOrDefault(x => x.Id == model.SelectedTournamentId);
            }

            if (model.SelectedDisciplineId != Guid.Empty)
            {
                model.SelectedDiscipline = Session.Query <Discipline>().FirstOrDefault(x => x.Id == model.SelectedDisciplineId);

                model.Categories = model.SelectedDiscipline.Categories;

                if (model.SelectedDiscipline.Categories.Count == 1)
                {
                    model.SelectedCategory   = model.SelectedDiscipline.Categories[0];
                    model.SelectedCategoryId = model.SelectedDiscipline.Categories[0].Id;
                }
            }

            if (model.SelectedCategoryId != Guid.Empty)
            {
                model.SelectedCategory = Session.Query <Category>().FirstOrDefault(x => x.Id == model.SelectedCategoryId);
                model.AgeGroups        = model.SelectedCategory.AgeGroups;

                if (model.SelectedCategory.AgeGroups.Count == 1)
                {
                    model.SelectedAgeGroup   = model.SelectedCategory.AgeGroups[0];
                    model.SelectedAgeGroupId = model.SelectedCategory.AgeGroups[0].Id;
                }
            }

            if (model.SelectedAgeGroupId != Guid.Empty)
            {
                model.SelectedAgeGroup = Session.Query <AgeGroup>().FirstOrDefault(x => x.Id == model.SelectedAgeGroupId);

                try
                {
                    model.RegisteredMembers = Session.Query <CategoryMember>().Where(x => x.Category == model.SelectedCategory && x.AgeGroup == model.SelectedAgeGroup && x.Club == model.CurrentClub).ToList();
                }
                catch (NullReferenceException ex)
                {
                    model.RegisteredMembers = new List <CategoryMember>();
                }
            }

            if (string.IsNullOrWhiteSpace(model.SelectedClubMembers))
            {
                ModelState.AddModelError("Invalid number of participants", String.Format("В тази категория може да има минимум {0} участник/а", model.SelectedCategory.MinNumberOfParticipants));

                return(View("Index", model));
            }

            var selectedClubMembersIds = model.SelectedClubMembers.Remove(0, 1).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            if (selectedClubMembersIds.Count < model.SelectedCategory.MinNumberOfParticipants)
            {
                ModelState.AddModelError("Invalid number of participants", String.Format("В тази категория може да има минимум {0} участник/а", model.SelectedCategory.MinNumberOfParticipants));

                return(View("Index", model));
            }

            var selectedClubMembers = new List <Participant>();

            var lowerAgeParticipants = 0;

            foreach (var id in selectedClubMembersIds)
            {
                var participant = Session.Query <Participant>().FirstOrDefault(x => x.Id.ToString().ToLower() == id.Trim());

                if (selectedClubMembers.Contains(participant))
                {
                    ModelState.AddModelError("Participant exists", String.Format("Този участник: {0} {1} {2} {3} вече участва в тази {4}", participant.FirstName, participant.MiddleName, participant.LastName, participant.EGN, model.SelectedCategory.CategoryName));

                    return(View("Index", model));
                }

                selectedClubMembers.Add(participant);

                foreach (var member in model.SelectedCategory.CategoryMembers)
                {
                    if (member.Participants.Contains(participant))
                    {
                        ModelState.AddModelError("Participant exists", String.Format("Този участник: {0} {1} {2} {3} вече участва в тази категория", participant.FirstName, participant.MiddleName, participant.LastName, participant.EGN));

                        return(View("Index", model));
                    }
                }

                var age = GetAgeFromEGN(participant.EGN);

                if (age < model.SelectedAgeGroup.MinimumAge)
                {
                    lowerAgeParticipants++;
                }
            }

            var lowerAgeParticipantsPercentage = 0.0;

            if (lowerAgeParticipants > 0)
            {
                lowerAgeParticipantsPercentage = lowerAgeParticipants / selectedClubMembersIds.Count * 100;
            }

            if (lowerAgeParticipantsPercentage > 50)
            {
                ModelState.AddModelError("Invalid participants", "Не може да имате повече от 50% участници от друга възрастова група");

                return(View("Index", model));
            }

            if (string.IsNullOrWhiteSpace(model.DanceName))
            {
                ModelState.AddModelError("DanceName", "Името на танца е задължително");

                return(View("Index", model));
            }

            if (model.SelectedCategory.CategoryMembers == null)
            {
                model.SelectedCategory.CategoryMembers = new List <CategoryMember>();
            }

            var categoryMember = new CategoryMember();

            categoryMember.Participants = new List <Participant>();
            categoryMember.Category     = model.SelectedCategory;
            categoryMember.Name         = model.DanceName;
            categoryMember.AgeGroup     = model.SelectedAgeGroup;
            categoryMember.Club         = Session.Query <User>().FirstOrDefault(x => x.Id == SecurityManager.AuthenticatedUser.Id).Club;

            Session.Save(categoryMember);

            categoryMember.Participants = selectedClubMembers;

            model.SelectedCategory.CategoryMembers.Add(categoryMember);

            Session.SaveOrUpdate(model.SelectedCategory);

            model.DanceName           = string.Empty;
            model.SelectedClubMembers = string.Empty;

            try
            {
                model.RegisteredMembers = Session.Query <CategoryMember>().Where(x => x.Category == model.SelectedCategory && x.AgeGroup == model.SelectedAgeGroup && x.Club == model.CurrentClub).ToList();
            }
            catch (NullReferenceException ex)
            {
                model.RegisteredMembers = new List <CategoryMember>();
            }

            return(View("Index", model));
        }
示例#3
0
 public void Update(CategoryMember entity)
 {
     _CategoryMemberRepository.Update(entity);
 }
示例#4
0
 public CategoryMember Insert(CategoryMember entity)
 {
     return(_CategoryMemberRepository.Add(entity));
 }
示例#5
0
 public void Delete(CategoryMember entity)
 {
     _CategoryMemberRepository.Delete(entity);
 }
        private void gridViewEdit_ValidateRow(object sender, ValidateRowEventArgs e)
        {
            ColumnView view = sender as ColumnView;
            GridColumn col  = view.Columns["UseName"];
            string     temp = (string)view.GetRowCellValue(e.RowHandle, col);

            if (temp == null || temp.Length <= 4)
            {
                e.Valid = false;
                view.SetColumnError(col, "The usename's length must be more 4 character!");
            }

            col  = view.Columns["PassWord"];
            temp = (string)view.GetRowCellValue(e.RowHandle, col);
            if (temp == null || temp.Length <= 3)
            {
                e.Valid = false;
                view.SetColumnError(col, "The password's length must be more 3 character!");
            }

            col  = view.Columns["FirstName"];
            temp = (string)view.GetRowCellValue(e.RowHandle, col);
            if (temp == null || temp.Length <= 0)
            {
                e.Valid = false;
                view.SetColumnError(col, "The Frist name doesn't accept null!");
            }

            col  = view.Columns["LastName"];
            temp = (string)view.GetRowCellValue(e.RowHandle, col);
            if (temp == null || temp.Length <= 0)
            {
                e.Valid = false;
                view.SetColumnError(col, "The Last name doesn't accept null!");
            }

            Member m = gridViewEdit.GetRow(e.RowHandle) as Member;

            col = view.Columns["BirthDate"];
            if (!TestBirthDate(m.BirthDate))
            {
                e.Valid = false;
                view.SetColumnError(col, "The age must less than 150 and more than 16!");
            }

            col = view.Columns["City"];
            if (m.Address == null || m.Address.Length <= 0)
            {
                e.Valid = false;
                view.SetColumnError(col, "The address filde doesn't accept null!");
            }

            col = view.Columns["CategoryInfo"];
            CategoryMember cat = view.GetRowCellValue(e.RowHandle, col) as CategoryMember;

            if (!(cat != null))
            {
                e.Valid = false;
                view.SetColumnError(col, "The CategoryInfo filde doesn't accept null!");
            }

            if (e.Valid == false)
            {
                saveToolStripMenuItem.Enabled = false;
            }
            else
            {
                saveToolStripMenuItem.Enabled = true;
            }
        }
示例#7
0
 public bool Update(CategoryMember entity)
 {
     return(_categoryMemberRepository.Update(entity));
 }
示例#8
0
 public bool Insert(CategoryMember entity)
 {
     return(_categoryMemberRepository.Insert(entity));
 }