コード例 #1
0
        public async Task <IActionResult> AddProfile(Swimmer swimmer)
        {
            var currentUserId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (db.Swimmers.Any(i => i.UserId == currentUserId))
            {
                var swimmerToUpdate = db.Swimmers.FirstOrDefault(i => i.UserId == currentUserId);
                swimmerToUpdate.Name = swimmer.Name;
                db.Update(swimmerToUpdate);
            }
            else
            {
                db.Add(swimmer);
            }
            await db.SaveChangesAsync();

            return(View("Index"));
        }
コード例 #2
0
        public async Task <IActionResult> AddProfile(Coach coach)
        {
            var currentUserId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (db.Coaches.Any(c => c.UserId == currentUserId))
            {
                var coachToUpdate = db.Coaches.FirstOrDefault(c => c.UserId == currentUserId);
                coachToUpdate.Name        = coach.Name;
                coachToUpdate.PhoneNumber = coach.PhoneNumber;
                db.Update(coachToUpdate);
            }
            else
            {
                db.Add(coach);
            }
            await db.SaveChangesAsync();

            return(View("Index"));
        }