예제 #1
0
        public async Task <IActionResult> PutDiscipline(Guid id, DisciplineDTO discipline)
        {
            if (id != discipline.Id)
            {
                return(BadRequest());
            }

            var find = await _context.Disciplines.FindAsync(id);

            _context.Entry(find).State = EntityState.Modified;
            find.Name      = discipline.Name;
            find.OwnerId   = discipline.OwnerId;
            find.ShortName = discipline.ShortName;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                if (!DisciplineExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    _logger.LogError(ex.Message);
                    return(StatusCode(500));
                }
            }

            return(NoContent());
        }
예제 #2
0
        public List <TimeDTO> GetTimesByPeople(List <PersonDTO> personDtos, DisciplineDTO disciplineDto, DateTime[] timeScope)
        {
            var whereStatement = "WHERE (";
            var parameters     = new List <string>();
            var i = 0;

            for (; i < personDtos.Count; i++)
            {
                whereStatement += $"FK_P = @var{i} OR ";
                parameters.Add(personDtos[i].Pk.ToString());
            }

            string fromTo = _getTimeScope(timeScope);

            whereStatement += $"FK_P = 0) AND FK_D = @var{i} AND {fromTo} ORDER BY [Date] ASC, FK_D, FK_P, Seconds, PK;";
            parameters.Add(disciplineDto.Pk.ToString());

            var cmd = AssembleQuery(whereStatement);

            var times  = new List <TimeDTO>();
            var dbObjs = ReadParamterized(cmd, parameters);

            dbObjs.ForEach(TimeDTO => times.Add(TimeDTO));

            return(times);
        }
        public ActionResult CreateDiscipline(DisciplineViewModel disciplineViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var disciplineDTO = new DisciplineDTO
                    {
                        Name = disciplineViewModel.Name
                    };

                    disciplineService.CreateDiscipline(disciplineDTO);

                    TempData["message"] = string.Format("Дисциплина была добавлена");

                    return(RedirectToAction("index"));
                }
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError(ex.Property, ex.Message);
            }

            return(View(disciplineViewModel));
        }
예제 #4
0
        /// <summary>
        /// Use this constructor if you do not want to use all people in the input file
        /// </summary>
        /// <param name="discipline">The discipline the times should belong to</param>
        /// <param name="people">A list of people to insert the times for</param>
        /// <param name="dates">The dates for the times</param>
        public ExcelWriter(DisciplineDTO discipline, List <PersonDTO> people, List <DateTime> dates)
        {
            this._discipline = discipline;
            this._people     = people;
            this._dates      = dates;

            CreateInputExcel();
        }
예제 #5
0
        /// <summary>
        /// Gets the n fastest people for discipline identified by discId
        /// </summary>
        /// <param name="n">How many people should be displayed</param>
        /// <param name="discipline">The discipline</param>
        /// <returns>The n fastest people for the specified discipline</returns>
        public TimeDTO[] GetTopNPeopleForDiscipline(int n, DisciplineDTO discipline)
        {
            var db       = (DataLayer.DbHandler.TimeHandler)_db;
            var allTimes = db.GetTimesByDisciplines(new List <DisciplineDTO> {
                discipline
            });

            return(GetTopNUniquePeople(n, allTimes));
        }
예제 #6
0
        /// <summary>
        /// Gets the n fastest people for discipline identified by discId
        /// </summary>
        /// <param name="n">How many people should be displayed</param>
        /// <param name="discipline">The discipline</param>
        /// <returns>The n fastest people for the specified discipline</returns>
        public TimeDTO[] GetTopNPeopleForDiscipline(int n, DisciplineDTO discipline, bool male)
        {
            var db       = (DataLayer.DbHandler.TimeHandler)_db;
            var allTimes = db.GetTimesByDisciplines(new List <DisciplineDTO> {
                discipline
            });
            var genderSeparatedTimes = allTimes.Where(t => t.Person.Male == male).ToList();

            return(GetTopNUniquePeople(n, genderSeparatedTimes));
        }
예제 #7
0
        /// <summary>
        /// Get the highscore of a person of a discipline
        /// </summary>
        /// <param name="person">The person</param>
        /// <param name="discipline">The discipline</param>
        /// <returns>A single <see cref="TimeDTO"/> object</returns>
        public TimeDTO GetHighscoreForPersonForDiscipline(PersonDTO person, DisciplineDTO discipline)
        {
            var db       = (DataLayer.DbHandler.TimeHandler)_db;
            var allTimes = db.GetTimesByDisciplines(new List <DisciplineDTO> {
                discipline
            }, person);
            var sortedTimes = allTimes.OrderBy(x => x.Seconds).ThenByDescending(x => x.Date);

            return(sortedTimes.FirstOrDefault());
        }
예제 #8
0
        /// <summary>
        /// Use this constructor if you want to use all people
        /// </summary>
        /// <param name="discipline">The discipline the times should belong to</param>
        /// <param name="dates">The dates for the times</param>
        public ExcelWriter(DisciplineDTO discipline, List <DateTime> dates)
        {
            this._discipline = discipline;
            this._dates      = dates;

            // get all people
            var dbObj = TimeHandler.GetAll();

            dbObj.ForEach(t => _people.Add(t.Person));


            CreateInputExcel();
        }
        public void CreateDiscipline(DisciplineDTO disciplineDTO)
        {
            if (disciplineDTO == null)
            {
                throw new ValidationException("Введите данные", "");
            }

            Discipline discipline = new Discipline
            {
                Name = disciplineDTO.Name
            };

            Database.Disciplines.Create(discipline);
            Database.Save();
        }
예제 #10
0
        public async Task <IActionResult> Create([FromBody] DisciplineDTO model)
        {
            Discipline discipline = new Discipline {
                Name = model.Name, Cipher = model.Cipher
            };

            try
            {
                await _db.Disciplines.AddAsync(discipline);

                await _db.SaveChangesAsync();
            }
            catch (DbUpdateException e)
            {
                await Response.WriteAsync(e.Message);
            }
            return(Ok(model));
        }
예제 #11
0
        public async Task <IActionResult> Update([FromBody] DisciplineDTO model)
        {
            var disciplineUpdate = await _db.Disciplines.FirstOrDefaultAsync(d => d.Cipher == model.Cipher);

            if (disciplineUpdate != null)
            {
                try
                {
                    disciplineUpdate.Name = model.Name;
                    _db.Disciplines.Update(disciplineUpdate);
                    await _db.SaveChangesAsync();
                }
                catch (DbUpdateException e)
                {
                    await Response.WriteAsync(e.Message);
                }
                return(Ok());
            }
            return(NotFound());
        }
예제 #12
0
        public List <TimeDTO> GetTimesByPeople(List <PersonDTO> personDtos, DisciplineDTO disciplineDto)
        {
            var whereStatement = "WHERE (";
            var parameters     = new List <string>();
            var i = 0;

            for (; i < personDtos.Count; i++)
            {
                whereStatement += $"FK_P = @var{i} OR ";
                parameters.Add(personDtos[i].Pk.ToString());
            }

            whereStatement += $"FK_P = 0) AND FK_D = @var{i}";
            parameters.Add(disciplineDto.Pk.ToString());

            var cmd = AssembleQuery(whereStatement);

            var times  = new List <TimeDTO>();
            var dbObjs = ReadParamterized(cmd, parameters);

            dbObjs.ForEach(TimeDTO => times.Add(TimeDTO));

            return(times);
        }
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var discipline = await _context.Discipline.FindAsync(id);

            var usersIn = _context.UserDiscipline.Where(x => x.DisciplineId == id).ToList();

            if (discipline == null)
            {
                return(NotFound());
            }
            var model = new DisciplineDTO
            {
                discipline = discipline,
                UserIn     = usersIn,
                Users      = _userManager.Users.ToList()
            };

            return(View(model));
        }
예제 #14
0
        public List <TimeDTO> GetTimesByPeople(List <PersonDTO> people, DisciplineDTO discipline, DateTime[] timescope)
        {
            var db = (DataLayer.DbHandler.TimeHandler)_db;

            return(db.GetTimesByPeople(people, discipline, _getTimescope(timescope)));
        }
예제 #15
0
        protected override List <RelayDTO> ReadParamterized(string cmd, List <string> parameters)
        {
            var relays = new List <RelayDTO>();

            using (SqlConnection con = new SqlConnection(_readerConnectionString))
            {
                try
                {
                    var query = new SqlCommand(cmd, con);
                    AddParameters(query, parameters);
                    con.Open();

                    using (var sqlReader = query.ExecuteReader())
                    {
                        RelayDTO tmpRelay;
                        while (sqlReader.Read())
                        {
                            tmpRelay = GetRelayDto
                                       (
                                sqlReader.GetInt32(0),
                                sqlReader.GetString(1)
                                       );

                            // Checking if the relay already exists in the list
                            var existingRelay = relays.FirstOrDefault(r => r.Pk == tmpRelay.Pk);

                            // if not, add the current relay to the list
                            if (existingRelay == null)
                            {
                                relays.Add(tmpRelay);
                                existingRelay = tmpRelay;
                            }

                            if (sqlReader.IsDBNull(2) || sqlReader.IsDBNull(3) || sqlReader.IsDBNull(4) || sqlReader.IsDBNull(5))
                            {
                                continue;
                            }

                            // assemble the Discipline object
                            var tmpDiscipline = new DisciplineDTO
                            {
                                Pk       = sqlReader.GetInt32(3),
                                DiscName = sqlReader.GetString(4),
                                Meters   = sqlReader.GetInt32(5)
                            };

                            // assemble the RelayDiscipline object
                            var tmpRelayDiscipline = new RelayDisciplineDTO
                            {
                                Pk         = sqlReader.GetInt32(2),
                                FK_R       = existingRelay.Pk,
                                FK_D       = tmpDiscipline.Pk,
                                Relay      = existingRelay,
                                Discipline = tmpDiscipline
                            };

                            // Add the RelayDiscipline to the relay
                            tmpRelay.RelaysDisciplines = new List <RelayDisciplineDTO>();
                            existingRelay.RelaysDisciplines.Add(tmpRelayDiscipline);
                        }
                    }
                }
                catch (SqlException e)
                {
                    throw new Exception(e.Message);
                }
                catch (Exception e)
                {
                    throw;
                }
            }

            return(relays);
        }