Пример #1
0
        public ActionResult Create()
        {
            var empty = new UserTypeViewModel();
            var data  = empty.ToVM();

            return(View(data));
        }
Пример #2
0
        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());
        }
Пример #3
0
        public void AddUserTypes(UserTypeViewModel entity)
        {
            var model = _mapper.Map <UserType>(entity);

            _repository.Add(model);
            _unitOfWork.Commit();
        }
Пример #4
0
 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"));
 }
Пример #5
0
        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 }));
            }
        }
Пример #9
0
 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));
        }
Пример #13
0
 public ActionResult Create(UserTypeViewModel model)
 {
     return(View("Index"));
 }
Пример #14
0
        /// <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);
        }