Example #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            AgeGroupModel ageGroupModel = db.AgeGroup.Find(id);

            db.AgeGroup.Remove(ageGroupModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #2
0
 public ActionResult Edit([Bind(Include = "AgeGroupID,AgeGroupName")] AgeGroupModel ageGroupModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ageGroupModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ageGroupModel));
 }
Example #3
0
        public ActionResult Create([Bind(Include = "AgeGroupID,AgeGroupName")] AgeGroupModel ageGroupModel)
        {
            if (ModelState.IsValid)
            {
                db.AgeGroup.Add(ageGroupModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(ageGroupModel));
        }
        private Comp_AgeGroupModel SaveOneAgeGroup(CompetitionModel comp, Comp_AgeGroupApiModel group)
        {
            var compYear = comp.Start.Year;
            var minAge   = compYear - group.YearYoung;
            var maxAge   = compYear - group.YearOld;

            bool noMaxLimit = (maxAge > 80);
            bool noMinLimit = (minAge < 3);

            Gender gender = group.Female ? Gender.Female : Gender.Male;
            IEnumerable <AgeGroupModel> exGroupList = db.AgeGroups.Where(g => g.GenderCode == (int)gender);

            if (noMaxLimit)
            {
                exGroupList = exGroupList.Where(g => (g.MaxAge ?? 100) > 80);
            }
            else if (noMinLimit)
            {
                exGroupList = exGroupList.Where(g => (g.MinAge ?? 0) < 4);
            }
            else
            {
                exGroupList = exGroupList.Where(g => g.MaxAge == maxAge && g.MinAge == minAge);
            }

            AgeGroupModel exGroup = exGroupList.FirstOrDefault();

            if (exGroup == null)
            {
                exGroup = new AgeGroupModel
                {
                    FullName          = group.Name,
                    SecretaryName     = group.Name,
                    MaxAge            = noMaxLimit ? null : new int?(maxAge),
                    MinAge            = (noMaxLimit || noMinLimit) ? null : new int?(minAge),
                    GenderProperty    = gender,
                    CompetitionGroups = new List <Comp_AgeGroupModel>()
                };
                db.AgeGroups.Add(exGroup);
            }
            Comp_AgeGroupModel groupComp = exGroup.CompetitionGroups.FirstOrDefault(cg => cg.CompetitionId == comp.Iid);

            if (groupComp == null)
            {
                groupComp = new Comp_AgeGroupModel {
                    CompetitionId = comp.Iid
                };
                exGroup.CompetitionGroups.Add(groupComp);
            }
            return(groupComp);
        }
Example #5
0
        // GET: AgeGroupModels/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AgeGroupModel ageGroupModel = db.AgeGroup.Find(id);

            if (ageGroupModel == null)
            {
                return(HttpNotFound());
            }
            return(View(ageGroupModel));
        }
Example #6
0
        /// <summary>
        /// Get all data from from AgeGroup
        /// </summary>
        /// <param name="iSqlFactory"></param>
        /// <returns>list</returns>
        public ListAgeGroup GetAgeGroup(ISqlFactory iSqlFactory)
        {
            ListAgeGroup lAgeGroup = new ListAgeGroup();

            lAgeGroup.ListOfAgeGroup = new List <AgeGroupModel>();
            try
            {
                DbDataReader datareader;
                DbCommand    command;
                string       sqlcommand = "SELECT * From AgeGroup";
                using (DbConnection conn = iSqlFactory.CreateConnection())
                {
                    conn.Open();

                    command    = iSqlFactory.ExecuteCommand(sqlcommand, conn);
                    datareader = command.ExecuteReader();

                    while (datareader.Read())
                    {
                        var ageGroup = new AgeGroupModel();

                        ageGroup.Id          = Convert.ToInt32(datareader["Id"]);
                        ageGroup.MinAge      = Convert.ToInt32(datareader["MinAge"] == DBNull.Value ? null : datareader["MinAge"]);
                        ageGroup.MaxAge      = Convert.ToInt32(datareader["MaxAge"] == DBNull.Value ? null : datareader["MaxAge"]);
                        ageGroup.Description = datareader["Description"].ToString();

                        lAgeGroup.ListOfAgeGroup.Add(ageGroup);
                    }
                }
            }
            catch (DbException ex)
            {
                lAgeGroup.Message.Add(new Response
                {
                    MessageCode    = "Error",
                    MessageDetails = ex.Message
                });
            }


            return(lAgeGroup);
        }
Example #7
0
 public Comp_AgeGroupEdit(AgeGroupModel grp, bool confirmed = false)
 {
     this.GroupId   = grp.Iid;
     this.Name      = grp.FullName;
     this.Confirmed = confirmed;
 }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            ValidationResult vRes;
            DateTime?        val;

            vRes = validateExpression(m => m.StartDateText, out val);
            if (vRes == null)
            {
                this.StartDate = val;
            }
            else
            {
                yield return(vRes);
            }

            vRes = validateExpression(m => m.StopDateText, out val);
            if (vRes == null)
            {
                this.StopDate = val;
            }
            else
            {
                yield return(vRes);
            }

            vRes = validateExpression(m => m.ApplicationsEndDateString, out val);
            if (vRes == null)
            {
                this.ApplicationsEndDate = val;
            }
            else
            {
                yield return(vRes);
            }

            vRes = validateExpression(m => m.ApplicationsEditEndDateString, out val);
            if (vRes == null)
            {
                this.ApplicationsEditEndDate = val;
            }
            else
            {
                yield return(vRes);
            }

            DateTime startDate  = this.StartDate ?? DateTime.MinValue;
            DateTime stopDate   = this.StopDate ?? DateTime.MaxValue;
            DateTime appEnd     = this.ApplicationsEndDate ?? DateTime.MinValue;
            DateTime appEditEnd = this.ApplicationsEditEndDate ?? DateTime.MinValue;

            if (stopDate < startDate)
            {
                yield return(new ValidationResult("Дата окончания должна быть больше или равной дате начала", new String[] { "StopDate" }));
            }
            if (appEditEnd < appEnd)
            {
                yield return(new ValidationResult("Дата окончания корректировок заявок должна быть больше или равной дате окончания заявок", new String[] { "ApplicationsEditEndDate" }));
            }
            if (appEditEnd > startDate)
            {
                yield return(new ValidationResult("Дата окончания корректировки заявок должан быть меньше или равной дате начала", new String[] { "ApplicationsEditEndDate" }));
            }
            if (!(Lead || Speed || Boulder))
            {
                yield return(new ValidationResult("Виды не выбраны"));
            }
            if (ageGroups == null || ageGroups.Count(g => g.Confirmed) < 1)
            {
                yield return(new ValidationResult("Группы не выбраны"));
            }
            if (ageGroups != null)
            {
                ClimbingContext db = new ClimbingContext();
                Dictionary <int, AgeGroupModel> groups = new Dictionary <int, AgeGroupModel>();
                foreach (var agr in ageGroups.Where(g => g.Confirmed))
                {
                    AgeGroupModel a = GetAgeGroup(db, groups, agr);
                    if (a == null)
                    {
                        yield return(new ValidationResult(String.Format("Группа с ID={0} не найдена.", agr.GroupId)));

                        continue;
                    }
                    int minAge      = a.MinAge ?? int.MinValue;
                    int maxAge      = a.MaxAge ?? int.MaxValue;
                    var crossGroups = ageGroups
                                      .Where(g => g.Confirmed)
                                      .Select(g => GetAgeGroup(db, groups, g))
                                      .Where(g => g != null)
                                      .Where(g => g.Iid != a.Iid)
                                      .Where(g => g.GenderCode == a.GenderCode &&
                                             (minAge >= (g.MinAge ?? int.MinValue) && minAge <= (g.MaxAge ?? int.MaxValue) ||
                                              maxAge >= (g.MinAge ?? int.MinValue) && maxAge <= (g.MaxAge ?? int.MaxValue)
                                             )).ToList();
                    if (crossGroups.Count < 1)
                    {
                        continue;
                    }
                    crossGroups.Sort();
                    StringBuilder sb = new StringBuilder();
                    foreach (var g in crossGroups)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(", ");
                        }
                        sb.Append(g.FullName);
                    }
                    yield return(new ValidationResult(String.Format("Группа {0} пересекается с группами {1}", a.FullName, sb.ToString())));
                }
            }
        }