コード例 #1
0
ファイル: EventController.cs プロジェクト: rafaliusz/TIM
        public IHttpActionResult Add(EventDTO ev)
        {
            try
            {
                Event eventEntity = Mapper.Map<EventDTO, Event>(ev);
                _db.Event.Add(eventEntity);
                _db.SaveChanges();

                InsertIntoTable(ev.AthleteIds, eventEntity.EventId, "AthletesEvents(EventId, AthleteId)");
                InsertIntoTable(ev.TeamIds, eventEntity.EventId, "TeamsEvents(EventId, TeamId)");
                InsertIntoTable(ev.UserIds, eventEntity.EventId, "UsersFavEvents(EventId, AthleteId)");

                //if (ev.TeamIds != null && ev.TeamIds.Count > 0)
                //{
                //    StringBuilder teamsQuery = new StringBuilder("INSERT INTO TeamsEvents(EventId, TeamId)");
                //    teamsQuery.Append(" VALUES");

                //    for (int i = 0; i < ev.AthleteIds.Count; i++)
                //    {
                //        if (i != 0)
                //            teamsQuery.Append(',');

                //        teamsQuery.Append("(" + eventEntity.EventId.ToStringIgnoreFraction() + ", " + ev.TeamIds.ElementAt(i).ToStringIgnoreFraction() + ")");
                //    }

                //    _db.Database.ExecuteSqlCommand(teamsQuery.ToString());
                //}

                //if (ev.UserIds != null && ev.UserIds.Count > 0)
                //{
                //    StringBuilder usersQuery = new StringBuilder("INSERT INTO UsersFavEvents(UserId, EventId)");
                //    usersQuery.Append(" VALUES");

                //    for (int i = 0; i < ev.AthleteIds.Count; i++)
                //    {
                //        if (i != 0)
                //            usersQuery.Append(',');

                //        usersQuery.Append("(" + eventEntity.EventId.ToStringIgnoreFraction() + ", " + ev.UserIds.ElementAt(i).ToStringIgnoreFraction() + ")");
                //    }

                //    _db.Database.ExecuteSqlCommand(usersQuery.ToString());
                //}

                _db.SaveChanges();

                return
                    new ItemCreatedHttpResult<Event>(eventEntity, Request, eventEntity.EventId, "GetEventById");
            }
            catch (Exception ex)
            {
                HttpResponseMessage responseMsg = new HttpResponseMessage(HttpStatusCode.Conflict);
                responseMsg.Content = new StringContent(/*ex.Message.ToString()*/"Something went really f*****g wrong.",
                                                            Encoding.UTF8, "text/plain");
                IHttpActionResult response = ResponseMessage(responseMsg);

                return response;
            }
        }
コード例 #2
0
ファイル: EventRepository.cs プロジェクト: rafaliusz/TIM
        private async Task<bool> Add(EventDTO ev)
        {
            HttpResponseMessage response =
                await _client.PostAsJsonAsync<EventDTO>(string.Format("api/event/"), ev)
                                        .ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                return true;
            }
            else
                return false;
        }
コード例 #3
0
ファイル: EventViewModel.cs プロジェクト: rafaliusz/TIM
 public EventViewModel(EventDTO evDto)
 {
     this.EventId = evDto.EventId;
     this.Name = evDto.Name;
     this.Sport = evDto.Sport;
     this.Longitude = evDto.Longitude;
     this.Latitude = evDto.Latitude;
     this.Individual = evDto.Individual;
     this.StartDate = evDto.StartDate;
     this.EndDate = evDto.EndDate;
     this.AthleteIds = evDto.AthleteIds;
     this.TeamIds = evDto.TeamIds;
     this.UserIds = evDto.UserIds;
 }
コード例 #4
0
ファイル: EventViewModel.cs プロジェクト: rafaliusz/TIM
        public EventViewModel(EventDTO evDto, ITeamRepository _teamRepo, IAthleteRepository _athRepo)
        {
            this.EventId = evDto.EventId;
            this.Name = evDto.Name;
            this.Sport = evDto.Sport;
            this.Longitude = evDto.Longitude;
            this.Latitude = evDto.Latitude;
            this.Individual = evDto.Individual;
            this.StartDate = evDto.StartDate;
            this.EndDate = evDto.EndDate;
            this.AthleteIds = evDto.AthleteIds;
            this.TeamIds = evDto.TeamIds;
            this.UserIds = evDto.UserIds;

            this.allTeams = _teamRepo.GetAll();
            this.allAthletes = _athRepo.GetAll();
            this.allSports = ItemListCreator.SportsList();
        }
コード例 #5
0
ファイル: EventDTO.cs プロジェクト: jackjet870/TIM
        public static IEnumerable <EventDTO> CreateArray(IEnumerable <Event> events)
        {
            int count = events.Count();

            if (count > 0)
            {
                EventDTO[] eventDtos = new EventDTO[count];

                for (int i = 0; i < count; i++)
                {
                    eventDtos[i] = new EventDTO(events.ElementAt(i));
                }

                return(eventDtos);
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
ファイル: EventRepository.cs プロジェクト: rafaliusz/TIM
 bool IEventRepository.Update(EventDTO ev)
 {
     Task<bool> isModified = Update(ev);
     return isModified.Result;
 }
コード例 #7
0
ファイル: EventRepository.cs プロジェクト: rafaliusz/TIM
 bool IEventRepository.Add(EventDTO ev)
 {
     Task<bool> addedSuccessfully = Add(ev);
     return addedSuccessfully.Result;            
 }
コード例 #8
0
ファイル: EventRepository.cs プロジェクト: rafaliusz/TIM
        private async Task<bool> Update(EventDTO ev)
        {
            HttpResponseMessage response = await _client.PutAsJsonAsync("api/event/", ev)
                    .ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                return true;
            }
            else
                return false;
        }
コード例 #9
0
ファイル: EventController.cs プロジェクト: rafaliusz/TIM
        public IHttpActionResult Update(EventDTO ev)
        {
            try
            {
                string query = "DELETE FROM TeamsEvents WHERE EventId=" + ev.EventId.ToStringIgnoreFraction();
                _db.Database.ExecuteSqlCommand(query);
                InsertIntoTable(ev.TeamIds, ev.EventId, "TeamsEvents(EventId, TeamId)");

                query = "DELETE FROM AthletesEvents WHERE EventId=" + ev.EventId.ToStringIgnoreFraction();
                _db.Database.ExecuteSqlCommand(query);
                InsertIntoTable(ev.AthleteIds, ev.EventId, "AthletesEvents(EventId, AthleteId)");

                query = "DELETE FROM UsersFavEvents WHERE EventId=" + ev.EventId.ToStringIgnoreFraction();
                _db.Database.ExecuteSqlCommand(query);
                InsertIntoTable(ev.UserIds, ev.EventId, "UsersFavEvents(EventId, UserId)");

                Event evToUpdate = _db.Event.Where(e => e.EventId == ev.EventId).First();

                evToUpdate.Name = ev.Name;
                evToUpdate.Sport = ev.Sport;
                evToUpdate.Individual = ev.Individual;
                evToUpdate.Latitude = ev.Latitude;
                evToUpdate.Longitude = ev.Longitude;
                _db.SaveChanges();

                return Ok();
            }
            catch (Exception ex)
            {
                return InternalServerError();
            }
        }
コード例 #10
0
ファイル: EventDTO.cs プロジェクト: rafaliusz/TIM
        public static IEnumerable<EventDTO> CreateArray(IEnumerable<Event> events)
        {
            int count = events.Count();

            if (count > 0)
            {
                EventDTO[] eventDtos = new EventDTO[count];

                for (int i = 0; i < count; i++)
                    eventDtos[i] = new EventDTO(events.ElementAt(i));

                return eventDtos;
            }
            else
                return null;
        }