예제 #1
0
        public async Task <IActionResult> Upsert()
        {
            PGEditViewModel pgEdit         = new PGEditViewModel();
            var             claimsIdentity = (ClaimsIdentity)User.Identity;
            var             claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            pgEdit.PG = await _unitOfWork.PG.GetAsync(claim.Value, true, true, false);


            if (pgEdit.PG == null)
            {
                pgEdit.PG = new PG();
                var facilities = await _unitOfWork.Facility.GetAllAsync();

                pgEdit.Facilities = facilities.ToList();
            }
            else
            {
                var facilities = await _unitOfWork.PG.GetFacilitiesForPG(pgEdit.PG.Id);

                pgEdit.Facilities = facilities.ToList();
            }

            IEnumerable <City> cities = await _unitOfWork.City.GetAllAsync();

            ViewBag.CityList = cities.Select(c => new SelectListItem()
            {
                Text  = c.Name,
                Value = c.Id.ToString()
            }).ToList();

            return(View(pgEdit));
        }
예제 #2
0
        public async Task <IActionResult> Upsert([FromForm] PGEditViewModel pgVM)
        {
            PGEditViewModel pgEdit         = new PGEditViewModel();
            var             claimsIdentity = (ClaimsIdentity)User.Identity;
            var             claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            PG pg = pgVM.PG;

            pg.ApplicationUserId = claim.Value;
            if (!pg.IsMale && !pg.IsFemale)
            {
                pg.IsMale = true;
            }

            await _unitOfWork.PG.Update(pg, pgVM.Facilities);

            return(RedirectToAction(nameof(Index)));
        }