Exemplo n.º 1
0
        private async Task <bool> AddRaceDistanceWherePreviousExists(RaceViewModel model,
                                                                     ICollection <RaceDistance> RaceDistances,
                                                                     IQueryable <Distance> distances)
        {
            bool isSaveSuccess = true;
            List <RaceDistance> assignedRaceDistances = new List <RaceDistance>();

            //foreach (var recordId in model.DistanceIds)
            //{

            //    var currentRolePermission = distances.Where(a => a.Id == recordId).FirstOrDefault();
            //    if (currentRolePermission != null)
            //    {

            //        if (!RaceDistances.Any(a => a.DistanceId == recordId))
            //        {
            //            // var currentUserRoleID = currentMenuRoles.First(a => a.Distance.RoleID == currentRolePermission.RoleID).RegionID;
            //            var RaceDistanceRepo = new RaceDistance();
            //            //assignedRaceDistances.Add(RaceDistanceRepo.ToEntity(recordId, model.Id, model.SessionUserId));
            //        }
            //    }


            //}

            for (int row = 0; row < model.DistanceIds.Count(); row++)
            {
                if (model.EventDateTimes[row] != null)
                {
                    var currentDistance = distances.Where(a => a.Id == model.DistanceIds[row]).FirstOrDefault();
                    if (currentDistance != null)
                    {
                        if (!RaceDistances.Any(a => a.DistanceId == model.DistanceIds[row]))
                        {
                            var RaceDistanceRepo = new RaceDistance();
                            assignedRaceDistances.Add(RaceDistanceRepo.ToEntity((int)model.DistanceIds[row], model.Id, (DateTime)model.EventDateTimes[row], model.SessionUserId));
                        }
                    }
                }
            }


            if (assignedRaceDistances.Count > 0)
            {
                await _context.RaceDistance.AddRangeAsync(assignedRaceDistances);

                await _context.SaveChangesAsync();

                isSaveSuccess = true;
            }

            return(isSaveSuccess);
        }
Exemplo n.º 2
0
        private async Task <bool> AddEntity(RaceViewModel model,
                                            ICollection <RaceDistance> raceDistances,
                                            IQueryable <Distance> distances)
        {
            bool isSaveSuccess = true;
            List <RaceDistance> RaceDistanceList = new List <RaceDistance>();

            //foreach (var record in model.DistanceIds)
            //{
            //    var currentDistance = distances.Any(a => a.Id == record);
            //    if (currentDistance)
            //    {
            //        RaceDistance raceDistance = new RaceDistance();
            //        RaceDistanceList.Add(raceDistance.ToEntity(record, model.Id, model.SessionUserId));
            //    }
            //}


            for (int row = 0; row < model.DistanceIds.Count(); row++)
            {
                if (model.EventDateTimes[row] != null)
                {
                    var currentDistance = distances.Any(a => a.Id == model.DistanceIds[row]);
                    if (currentDistance)
                    {
                        RaceDistance raceDistance = new RaceDistance();
                        RaceDistanceList.Add(raceDistance.ToEntity((int)model.DistanceIds[row], model.Id, (DateTime)model.EventDateTimes[row], model.SessionUserId));
                    }
                }
            }


            if (RaceDistanceList.Count > 0)
            {
                await _context.RaceDistance.AddRangeAsync(RaceDistanceList);

                await _context.SaveChangesAsync();

                isSaveSuccess = true;
            }

            return(isSaveSuccess);
        }