示例#1
0
        public async Task <IActionResult> Edit(EditInstruktorViewModel instruktor)
        {
            if (ModelState.IsValid)
            {
                string     id = instruktor.Id;
                Instruktor instruktorIzBaze = await userManager.FindByIdAsync(id) as Instruktor;


                if (instruktorIzBaze == null)
                {
                    return(NotFound());
                }
                instruktorIzBaze.Cin        = instruktor.Cin;
                instruktorIzBaze.ImePrezime = instruktor.ImePrezime;
                instruktorIzBaze.Obuka      = instruktor.Obuka;
                instruktorIzBaze.ObukaId    = instruktor.ObukaId;

                var result = await userManager.UpdateAsync(instruktorIzBaze);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home", new { message = $"Izmene profila uspešno sačuvane" }));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }

            return(View(instruktor));
        }
示例#2
0
        public async Task <IActionResult> Edit(string id)
        {
            if (id == userManager.GetUserId(User))
            {
                ApplicationUser user = await userManager.FindByIdAsync(id);

                Instruktor instruktor = user as Instruktor;

                if (user == null)
                {
                    return(View("PageNotFound"));
                }

                ObukeDropDownList(instruktor.ObukaId);
                CinoviDropDownList(instruktor.Cin);

                var model = new EditInstruktorViewModel()
                {
                    Id         = instruktor.Id,
                    UserName   = instruktor.UserName,
                    Cin        = instruktor.Cin,
                    ImePrezime = instruktor.ImePrezime,
                    Obuka      = instruktor.Obuka,
                    ObukaId    = instruktor.ObukaId,
                    Email      = instruktor.Email
                };

                return(View(model));
            }
            else
            {
                return(View("AccessDenied"));
            }
        }