Ejemplo n.º 1
0
        public async Task <bool> CreateRounds(UserRoundCompletedsDto newRounds)
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <UserRoundCompletedQuestionsDto, UserRoundCompletedQuestions>();
                cfg.CreateMap <UserRoundCompletedSituationsDto, UserRoundCompletedSituations>().ForMember(dto2 => dto2.UserRoundCompletedQuestions,
                                                                                                          map => map.MapFrom(x2 => x2.question));
                cfg.CreateMap <UserRoundCompletedsDto, UserRoundCompleteds>().ForMember(dto => dto.UserRoundCompletedSituations,
                                                                                        map => map.MapFrom(x => x.situation));
            });

            var mapper = config.CreateMapper();
            UserRoundCompleteds rounds = mapper.Map <UserRoundCompletedsDto, UserRoundCompleteds>(newRounds);

            _entities.UserRoundCompleteds.Add(rounds);
            try
            {
                await _entities.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public async Task <PictureBooksDto> Insert(PictureBooksDto data)
        {
            var attribute = _mapper.Map <PictureBooksDto, PictureBooks>(data);
            var result    = _context.PictureBooks.Add(attribute);
            var res       = await _context.SaveChangesAsync();

            data.Id = result.Entity.Id;
            return(data);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update the user details if user exist.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <bool> Update(string id, ApplicationUserDto model)
        {
            try
            {
                if (model.VoiceOver == null)
                {
                    model.VoiceOver = false;
                }

                if (model.BallFlight == null)
                {
                    model.BallFlight = "Multiple";
                }

                if (model.HandicapId < 1 || model.HandicapId > 4)
                {
                    model.HandicapId = 4;
                }

                if (_aguilaContext.AspNetUsers.Count(e => e.Id == id) > 0)
                {
                    AspNetUsers modUsers = _aguilaContext.AspNetUsers.Where(u => u.Id == id).Select(u => u).FirstOrDefault();
                    modUsers.Name              = model.Name;
                    modUsers.Address           = model.Address;
                    modUsers.City              = model.City;
                    modUsers.State             = model.State;
                    modUsers.Zip               = model.Zip;
                    modUsers.ClubType          = model.ClubType;
                    modUsers.Email             = model.Email;
                    modUsers.HandicapId        = model.HandicapId;
                    modUsers.Height            = model.Height;
                    modUsers.PhoneNumber       = model.PhoneNumber;
                    modUsers.Twitter           = model.Twitter;
                    modUsers.Weight            = model.Weight;
                    modUsers.Age               = model.Age;
                    modUsers.SevenIronDistance = model.SevenIronDistance;

                    modUsers.DriverDistance = model.DriverDistance;
                    modUsers.VoiceOver      = model.VoiceOver;
                    modUsers.BallFlight     = model.BallFlight;


                    await _aguilaContext.SaveChangesAsync();
                }
                else
                {
                    return(false);
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
            return(true);
        }
Ejemplo n.º 4
0
        public async Task <LrddatasDto> CreateLRD(LrddatasDto data)
        {
            if (data.LrddataId != 0)
            {
                Lrddatas lrdData = _mapper.Map <LrddatasDto, Lrddatas>(data);
                bool     result2 = _repo.LRDRepository.Update(data.LrddataId, lrdData);
                await _repo.SaveAsync();

                return(data);
            }
            else
            {
                Lrddatas lrdDatas = new Lrddatas();
                lrdDatas.Title           = data.Title;
                lrdDatas.VideoUrl        = data.VideoUrl;
                lrdDatas.ContentLocation = data.ContentLocation;
                lrdDatas.Text            = data.Text;
                lrdDatas.Lrdtype         = data.Lrdtype;
                var lrddataID = _entities.Lrddatas.Add(lrdDatas);
                await _entities.SaveChangesAsync();

                if (data.LrdattributesLookups != null)
                {
                    var lrdAttributeLookups = data.LrdattributesLookups.ToList();
                    for (int i = 0; i < lrdAttributeLookups.Count; i++)
                    {
                        LrdattributesLookups lrdAttribute = new LrdattributesLookups();
                        lrdAttribute.LrdattributesId  = lrdAttributeLookups[i].LrdattributesId;
                        lrdAttribute.LrdcategoryId    = lrdAttributeLookups[i].LrdcategoryId;
                        lrdAttribute.LrddataLrddataId = lrddataID.Entity.LrddataId;
                        _entities.LrdattributesLookups.Add(lrdAttribute);
                    }

                    var lrdId = await _entities.SaveChangesAsync();
                }
                LrddatasDto result = _mapper.Map <Lrddatas, LrddatasDto>(lrdDatas);
                return(result);
            }
        }
Ejemplo n.º 5
0
        public async Task <NewSituationViewDto> CreateSituation(NewSituationViewDto newSituation)
        {
            try
            {
                if (newSituation != null)
                {
                    Situations situation = new Situations();
                    situation.Name          = newSituation.Name;
                    situation.YdsToPin      = newSituation.YdsToPin;
                    situation.WindSpeed     = newSituation.WindSpeed;
                    situation.Elevation     = Convert.ToString(newSituation.Elevation);
                    situation.WindDirection = newSituation.WindDirection;
                    //situation.NotSituationHandicapId = newSituation.NotSituationHandicapId;
                    situation.StartCoordinate  = newSituation.StartCoordinate;
                    situation.TargetCoordinate = newSituation.TargetCoordinate;
                    //situation.BookId = newSituation.BookId;
                    //situation.ImageFileId = newSituation.ImageFileId;
                    situation.LineType            = newSituation.LineType;
                    situation.PinCoordinate       = newSituation.PinCoordinate;
                    situation.IsFirstHole         = newSituation.IsFirstHole;
                    situation.NextHoleSituationId = newSituation.NextHoleSituationId;
                    situation.VoiceOverUrl        = newSituation.VoiceOverUrl;
                    situation.IsBegining          = newSituation.VoiceOverUrl == null ? 2 : newSituation.IsBegining;
                    situation.SituationCategory   = _context.SituationCategories.Where
                                                        (c => c.Id == newSituation.SituationCategoryId)
                                                    .Select(c => c).FirstOrDefault();
                    situation.Book = _context.PictureBooks.Where
                                         (b => b.Id == newSituation.BookId)
                                     .Select(b => b).FirstOrDefault();
                    situation.ImageFile = _context.PictureBooks.Where
                                              (i => i.Id == newSituation.ImageFileId)
                                          .Select(i => i).FirstOrDefault();
                    situation.BookId      = situation.Book.Id;
                    situation.ImageFileId = situation.ImageFile.Id;
                    var sid = _context.Situations.Add(situation);
                    await _context.SaveChangesAsync();

                    //NewSituationAttributes
                    var sattributes = newSituation.AttributesId.ToList();
                    for (int i = 0; i < sattributes.Count; i++)
                    {
                        SituationAttributes situationAttributes = new SituationAttributes();
                        situationAttributes.AttributesId = sattributes[i];
                        situationAttributes.SituationId  = sid.Entity.Id;
                        _context.SituationAttributes.Add(situationAttributes);
                    }
                    await _context.SaveChangesAsync();

                    //NewSituationHandicap

                    if (newSituation.HandicapId != null)
                    {
                        var shandicaps = newSituation.HandicapId.ToList();
                        for (int i = 0; i < shandicaps.Count; i++)
                        {
                            SituationHandicaps situationHandicap = new SituationHandicaps();
                            situationHandicap.HandicapId  = shandicaps[i];
                            situationHandicap.SituationId = sid.Entity.Id;
                            var h = _context.SituationHandicaps.Add(situationHandicap);
                        }
                        await _context.SaveChangesAsync();
                    }

                    //NewSituationQuestions - NewSituationAnswers
                    if (newSituation.Questions != null)
                    {
                        var squestions = newSituation.Questions.ToList();
                        for (int i = 0; i < squestions.Count; i++)
                        {
                            SituationQuestions situationQuestions = new SituationQuestions();
                            situationQuestions.Question     = squestions[i].Question;
                            situationQuestions.SituationId  = sid.Entity.Id;
                            situationQuestions.SituationId1 = sid.Entity.Id;
                            var qestionId = _context.SituationQuestions.Add(situationQuestions);
                            await _context.SaveChangesAsync();

                            var sanswers = squestions[i].Answers.ToList();
                            for (int j = 0; j < sanswers.Count; j++)
                            {
                                Answers answers = new Answers();
                                answers.Answer               = sanswers[j].Answer;
                                answers.DidYouKnowLink       = sanswers[j].DidYouKnowLink;
                                answers.LessonLink           = sanswers[j].LessonLink;
                                answers.Response             = sanswers[j].Response;
                                answers.RulesLink            = sanswers[j].RulesLink;
                                answers.Score                = sanswers[j].Score;
                                answers.SituationQuestionsId = qestionId.Entity.Id;
                                answers.Qid = qestionId.Entity.Id;
                                _context.Answers.Add(answers);
                                await _context.SaveChangesAsync();
                            }
                        }
                    }
                    newSituation.Id = situation.Id;

                    return(newSituation);
                }
                return(null);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 6
0
 public async Task SaveAsync()
 {
     await entities.SaveChangesAsync();
 }