public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                var userId = User.Identity.GetUserName();
                if (userRoleRepository.GetRoleByUserName(userId) != null && userRoleRepository.GetRoleByUserName(userId).IdUserType == "Admin")
                {
                    RawUserTypesModel rawRolesModel = new RawUserTypesModel();

                    UpdateModel(rawRolesModel);

                    if (rawRolesRepository.IsDuplicateRawRole(rawRolesModel) == false)
                    {
                        rawRolesRepository.InsertRawRole(rawRolesModel);

                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        return(RedirectToAction("IndexError"));
                    }
                }
                else
                {
                    return(RedirectToAction("Contact", "Home"));
                }
            }
            catch
            {
                return(View("CreateRawUserType"));
            }
        }
        public ActionResult Edit(Guid id, FormCollection collection)
        {
            try
            {
                var userId = User.Identity.GetUserName();
                if (userRoleRepository.GetRoleByUserName(userId) != null && userRoleRepository.GetRoleByUserName(userId).IdUserType == "Admin")
                {
                    RawUserTypesModel rawRolesModel = new RawUserTypesModel();

                    UpdateModel(rawRolesModel);

                    rawRolesRepository.UpdateRawRole(rawRolesModel);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Contact", "Home"));
                }
            }
            catch
            {
                return(View("EditRawRoles"));
            }
        }
Beispiel #3
0
        public void UpdateRawRole(RawUserTypesModel roles)
        {
            RawUserType roleDb = dbContext.RawUserTypes.FirstOrDefault(x => x.IdUserTypes == roles.IdUserTypes);

            if (roleDb != null)
            {
                roleDb.IdUserTypes = roles.IdUserTypes;
                roleDb.Name        = roles.Name;
                dbContext.SubmitChanges();
            }
        }
Beispiel #4
0
 public bool IsDuplicateRawRole(RawUserTypesModel role)
 {
     if (GetRawRoleByName(role.Name) == null)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Beispiel #5
0
        private RawUserTypesModel MapDbObjectToModel(RawUserType dbRole)
        {
            RawUserTypesModel role = new RawUserTypesModel();

            if (dbRole != null)
            {
                role.IdUserTypes = dbRole.IdUserTypes;
                role.Name        = dbRole.Name;
                return(role);
            }

            return(null);
        }
Beispiel #6
0
        private RawUserType MapModelToDbObject(RawUserTypesModel role)
        {
            RawUserType roleDb = new RawUserType();

            if (role != null)
            {
                roleDb.IdUserTypes = role.IdUserTypes;
                roleDb.Name        = role.Name;
                return(roleDb);
            }

            return(null);
        }
        // GET: RawUserTypes/Details/5
        public ActionResult Details(Guid id)
        {
            var userId = User.Identity.GetUserName();

            if (userRoleRepository.GetRoleByUserName(userId) != null && userRoleRepository.GetRoleByUserName(userId).IdUserType == "Admin")
            {
                RawUserTypesModel rolesModel = rawRolesRepository.GetRawRoleById(id);
                return(View("DetailsRawRoles", rolesModel));
            }
            else
            {
                return(RedirectToAction("Contact", "Home"));
            }
        }
Beispiel #8
0
 public void InsertRawRole(RawUserTypesModel role)
 {
     role.IdUserTypes = Guid.NewGuid();
     dbContext.RawUserTypes.InsertOnSubmit(MapModelToDbObject(role));
     dbContext.SubmitChanges();
 }