public ActionResult Create() { var empty = new UserTypeViewModel(); var data = empty.ToVM(); return(View(data)); }
public async Task <IActionResult> PutUserType([FromRoute] int id, [FromBody] UserTypeViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userType = new UserType { Id = id, Name = model.Name }; _context.Entry(userType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserTypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void AddUserTypes(UserTypeViewModel entity) { var model = _mapper.Map <UserType>(entity); _repository.Add(model); _unitOfWork.Commit(); }
public ActionResult Create(UserTypeViewModel userType) { if (!ModelState.IsValid) { ErrorNotification("Kayıt Eklenemedi!"); return(RedirectToAction("Create")); } _userTypeService.Add(new UserType { //TODO:Alanlar buraya yazılacak //Örn:BrandName = brand.BrandName, }); SuccessNotification("Kayıt Eklendi."); return(RedirectToAction("UserTypeIndex")); }
public async Task <IActionResult> PostUserType([FromBody] UserTypeViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userType = new UserType { Name = model.Name }; _context.UserTypes.Add(userType); await _context.SaveChangesAsync(); return(CreatedAtAction("GetUserType", new { id = userType.Id }, userType)); }
// GET: Administrator/Details/5 public async Task <IActionResult> Details(string id) { AppUser user = await _userManager.FindByIdAsync(id.ToString()); IList <string> roleList = await _userManager.GetRolesAsync(user); UserTypeViewModel userTypeViewModel = new UserTypeViewModel { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Role = roleList.ToList().FirstOrDefault(), }; return(View(userTypeViewModel)); }
public async Task <ActionResult <UserTypeViewModel> > PostUserType(UserTypeViewModel viewModel) { try { var entity = _mapper.Map <UserType>(viewModel); var model = await _userTypeRepository.Add(entity); return(_mapper.Map <UserTypeViewModel>(model)); } catch (InvalidDataException e) { return(BadRequest(new { message = e.Message })); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, new { message = e.Message })); } }
public async Task <IActionResult> PatchUserType(int id, UserTypeViewModel viewModel) { try { var entity = _mapper.Map <UserType>(viewModel); await _userTypeRepository.Update(id, entity); return(NoContent()); } catch (UserTypeNotFoundException e) { return(NotFound(new { message = e.Message })); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, new { message = e.Message })); } }
bool IUserType.Insert(UserTypeViewModel model) { using (var ent = new CustomerSupportEntities()) { var newRow = new tblUserType(); newRow.UserTypeName = model.UserTypeName; newRow.UserTypes.Add(newRow); int success = ent.SaveChanges(); if (success > 0) { return true; } else { return false; } } }
// GET: Administrator/Edit/5 public async Task <IActionResult> Edit(string id) { AppUser user = await _userManager.FindByIdAsync(id); IList <string> roleList = await _userManager.GetRolesAsync(user); UserTypeViewModel userTypeViewModel = new UserTypeViewModel { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Role = roleList.ToList().FirstOrDefault(), }; ViewData["RoleNames"] = new SelectList(_roleManager.Roles.ToList(), "Name", "Name"); return(View(userTypeViewModel)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,Role,FirstName,LastName,Email")] UserTypeViewModel userTypeViewModel) { try { AppUser user = await _userManager.FindByIdAsync(id); user.FirstName = userTypeViewModel.FirstName; user.LastName = userTypeViewModel.LastName; user.Email = userTypeViewModel.Email; var identityResult = await _userManager.UpdateAsync(user); var identityRoleResult = await _userManager.AddToRoleAsync(user, userTypeViewModel.Role); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <IActionResult> Index() { var users = _userManager.Users; List <UserTypeViewModel> userTypeViewModels = new List <UserTypeViewModel>(); foreach (var user in users) { IList <string> roleList = await _userManager.GetRolesAsync(user); UserTypeViewModel userTypeViewModel = new UserTypeViewModel { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Role = roleList.ToList().FirstOrDefault(), }; userTypeViewModels.Add(userTypeViewModel); } return(View(userTypeViewModels)); }
public ActionResult Create(UserTypeViewModel model) { return(View("Index")); }
/// <summary> /// Gets the user Type details for a user /// </summary> /// <param name="userTypeID">user Type ID</param> /// <returns>role ID</returns> public UserTypeViewModel GetUserTypeByTypeId(int userTypeID) { UserTypeViewModel userTypeDetails = this.GetUserTypes().Where(x => x.UserTypeID == userTypeID).FirstOrDefault(); return(userTypeDetails); }