Exemple #1
0
        public async Task <IActionResult> Edit2(int?id)
        {
            {
                if (id == null)
                {
                    return(NotFound());
                }

                var teeTime = await _context.TeeTime.SingleOrDefaultAsync(m => m.TeeTimeId == id);

                if (teeTime == null)
                {
                    return(NotFound());
                }
                var model = new TeeAssignEditViewModel();
                model.TeeTime    = teeTime;
                model.ReservedBy = await _context.Member.SingleOrDefaultAsync(m => m.MemberId == teeTime.ReservedById);

                model.Course = await _context.Course.SingleOrDefaultAsync(m => m.CourseId == teeTime.CourseId);

                var teeAssigns = _teeAssignInfo.getAllForTeeTime(teeTime.TeeTimeId);
                var playIds    = new List <string>();
                foreach (var teeAssign in teeAssigns)
                {
                    playIds.Add(teeAssign.TeeAsign.PlayId.ToString());
                }
                model.PlayIds = playIds;
                model.Players = _playerInfo.getPlayers(teeTime.TeeTimeTS);

                return(View(model));
            }
        }
Exemple #2
0
        public async Task <IActionResult> Edit2(int id, List <string> playIds)
        {
            var teeTime = await _context.TeeTime.SingleOrDefaultAsync(m => m.TeeTimeId == id);

            if (teeTime == null)
            {
                return(NotFound());
            }
            var model = new TeeAssignEditViewModel();

            model.TeeTime    = teeTime;
            model.ReservedBy = await _context.Member.SingleOrDefaultAsync(m => m.MemberId == teeTime.ReservedById);

            model.Course = await _context.Course.SingleOrDefaultAsync(m => m.CourseId == teeTime.CourseId);

            var teeAssigns = _teeAssignInfo.getAllForTeeTime(teeTime.TeeTimeId);

            if (ModelState.IsValid)
            {
                try
                {
                    int i = 0;
                    foreach (TeeAssignInfo teeAssignInfo in teeAssigns)
                    {
                        TeeAssign teeAssign = teeAssignInfo.TeeAsign;
                        teeAssign.PlayId = 0;
                        if (playIds[i] != null)
                        {
                            teeAssign.PlayId = int.Parse(playIds[i]);
                        }
                        if (teeAssign.PlayId > 0)
                        {
                            Player player = await _context.Player.SingleOrDefaultAsync(m => m.PlayId == teeAssign.PlayId);

                            teeAssign.MemberId  = player.MemberId;
                            teeAssign.GuestName = "";
                            if (player.GuestName != null && player.GuestName.Length > 0)
                            {
                                teeAssign.GuestName = player.GuestName + ", Guest";
                            }
                        }
                        else
                        {
                            teeAssign.MemberId  = 0;
                            teeAssign.GuestName = "";
                            //if(teeAssign.TeeAssignId > 0) _context.TeeAssign.Remove(teeAssign);
                        }
                        teeAssign.Group = (int)Math.Floor((float)i / 4.0F) + 1;
                        teeAssign.Order = i % 4 + 1;
                        if (teeAssign.TeeAssignId == 0)
                        {
                            _context.Add(teeAssign);
                        }
                        else
                        {
                            _context.Update(teeAssign);
                        }
                        i++;
                    }

                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                }
                return(RedirectToAction(nameof(Index), "TeeTime"));
            }
            model.PlayIds = playIds;
            model.Players = _playerInfo.getPlayers(teeTime.TeeTimeTS);
            return(View(model));
        }