Exemplo n.º 1
0
        /// <summary>
        /// Checks Name
        /// </summary>
        /// <param name="viewModel">Injected <see cref="UpdateApplicationRole"/></param>
        /// <returns>Instance of <see cref="Task{ApplicationRole}"/></returns>
        public async Task <ApplicationRole> CheckName(UpdateApplicationRole @viewModel)
        {
            ApplicationRole @applicationRole = await Context.ApplicationRole
                                               .AsNoTracking()
                                               .TagWith("CheckName")
                                               .FirstOrDefaultAsync(x => x.Name == @viewModel.Name && x.Id != @viewModel.Id);

            if (@applicationRole != null)
            {
                // Log
                string @logData = @applicationRole.GetType().Name
                                  + " with Name "
                                  + applicationRole.Name
                                  + " was already found at "
                                  + DateTime.Now.ToShortTimeString();

                Logger.WriteGetItemFoundLog(@logData);

                throw new Exception(@applicationRole.GetType().Name
                                    + " with Name "
                                    + viewModel.Name
                                    + " already exists");
            }

            return(@applicationRole);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates Application Role
        /// </summary>
        /// <param name="viewModel">Injected <see cref="UpdateApplicationRole"/></param>
        /// <returns>Instance of <see cref="Task{ViewApplicationRole}"/></returns>
        public async Task <ViewApplicationRole> UpdateApplicationRole(UpdateApplicationRole @viewModel)
        {
            await CheckName(@viewModel);

            ApplicationRole @applicationRole = await FindApplicationRoleById(@viewModel.Id);

            @applicationRole.Name           = @viewModel.Name;
            @applicationRole.NormalizedName = @viewModel.Name;
            @applicationRole.ImageUri       = @viewModel.ImageUri;

            Context.ApplicationRole.Update(@applicationRole);

            await Context.SaveChangesAsync();

            // Log
            string @logData = @applicationRole.GetType().Name
                              + " with Id "
                              + @applicationRole.Id
                              + " was modified at "
                              + DateTime.Now.ToShortTimeString();

            Logger.WriteUpdateItemLog(@logData);

            return(Mapper.Map <ViewApplicationRole>(@applicationRole));
        }
Exemplo n.º 3
0
        public async Task UpdateApplicationRole()
        {
            UpdateApplicationRole viewModel = new UpdateApplicationRole()
            {
                Id       = Context.ApplicationRole.FirstOrDefault().Id,
                Name     = "Role 21",
                ImageUri = "URL/Role_21_500px.png",
            };

            await Service.UpdateApplicationRole(viewModel);

            Assert.Pass();
        }