Exemplo n.º 1
0
        public async Task <Response> Update(GroupUpdateModel GroupUpdateModel, ClaimsPrincipal user)
        {
            using (var context = _applicationDbContextFactory.Create())
            {
                var User = await _userManager.FindByNameAsync(user.Identity.Name);

                var Group = Mapper.Map <Group>(GroupUpdateModel);
                if (!context.Groups.Any(i => i.Id == Group.Id))
                {
                    return new Response {
                               Status = 500, Message = "Нет такой группы!"
                    }
                }
                ;
                if (!context.Check <Group>(Group.TeacherId))
                {
                    return new Response {
                               Status = 500, Message = "Такого курса нет!"
                    }
                }
                ;

                context.Groups.Update(Group);
                context.groupHistories.Add(new GroupHistory {
                    Action = "Создание", DateTime = DateTime.Now, GroupId = GroupUpdateModel.Id, UserId = User.Id
                });
                context.SaveChanges();
                return(new Response {
                    Status = 100, Message = "Запрос успешно прошел"
                });
            }
        }
Exemplo n.º 2
0
        public async Task <Group> InsertAsync(GroupUpdateModel group)
        {
            var result = await this.Context.AddAsync(this.Mapper.Map <DataAccess.Entities.Group>(group));

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <Group>(result.Entity));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> UpdateAsync(int groupId, [FromBody] GroupUpdateModel mGroup)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest(ModelStateError()));
            }

            var projectId = await _groupRepository.UpdateByIdAsync(groupId, mGroup);

            return(CreatedAtRoute("GetByGroupIdAsync", new { controller = "Groups", groupId = groupId }, mGroup));
        }
Exemplo n.º 4
0
        public async Task <Group> UpdateAsync(GroupUpdateModel group)
        {
            var existing = await this.Get(group);

            var result = this.Mapper.Map(group, existing);

            this.Context.Update(result);

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <Group>(result));
        }
Exemplo n.º 5
0
        public ActionResult Edit(Guid id)
        {
            var group     = _groupQueryService.GetGroup(id);
            var subgroups = _subgroupQueryService.MarkSelectedSubgroups(group);

            var vm = new GroupUpdateModel
            {
                Group     = group,
                Subgroups = subgroups
            };

            return(View(vm));
        }
Exemplo n.º 6
0
        public ActionResult Save(GroupUpdateModel model)
        {
            //if (!ModelState.IsValid)
            //{
            //    return View("Edit", model);
            //}

            if (ModelState.IsValid)
            {
                _groupCommandService.UpdateGroup(model);
                _groupCommandService.SetUserGroups(model);
            }

            return(RedirectToAction("Details", new { @id = model.Group.Id }));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> PutGroup(Guid id, GroupUpdateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var command = new UpdateGroupCommand
            {
                Id    = id,
                Input = model
            };

            return(await ExecuteRequest(command).ConfigureAwait(false));
        }
Exemplo n.º 8
0
        public void UpdateGroup(GroupUpdateModel input)
        {
            var user  = _userService.GetCurrentUser();
            var group = _groupQueryService.GetGroup(input.Group.Id);

            group.Name           = input.Group.Name;
            group.Description    = input.Group.Description;
            group.LastUpdateDate = DateTime.Now;
            group.LastUpdatedBy  = user.Identity.Name;

            using (var dbContextScope = _dbContextScopeFactory.Create())
            {
                var dbContext = dbContextScope.DbContexts.Get <EntityManagerDbContext>();

                dbContext.Set <Group>().AddOrUpdate(group);
                dbContext.SaveChanges();
            }
        }
Exemplo n.º 9
0
        public IActionResult UpdateGroup(GroupUpdateModel group)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var oldGroup = ChatStore.UsersByGroups.Find(x => x.GroupName == group.OldGroup);

            if (oldGroup == null)
            {
                return(NotFound());
            }
            else
            {
                oldGroup.GroupName = group.Group;
            }
            return(Ok());
        }
        public IActionResult Update(int id, [FromBody] GroupUpdateModel model)
        {
            var groups = _mapper.Map <Groups>(model);
            var user   = Utilities.getUserId(User);

            groups.Id = id;

            try
            {
                // update group
                var group = _groupService.Update(groups, user);
                return(Ok(_mapper.Map <GroupModel>(group)));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Exemplo n.º 11
0
        public async Task <IResultModel> Update(GroupUpdateModel model)
        {
            var entity = await _repository.GetAsync(model.Id);

            if (entity == null)
            {
                return(ResultModel.NotExists);
            }

            _mapper.Map(model, entity);

            //if (await _repository.Exists(entity))
            //{
            //return ResultModel.HasExists;
            //}

            var result = await _repository.UpdateAsync(entity);

            return(ResultModel.Result(result));
        }
Exemplo n.º 12
0
        public void SetUserGroups(GroupUpdateModel model)
        {
            using (var dbContextScope = _dbContextScopeFactory.Create())
            {
                var dbContext = dbContextScope.DbContexts.Get <EntityManagerDbContext>();

                var group     = _groupQueryService.GetGroup(model.Group.Id);
                var subgroups = _subgroupQueryService.GetAllSubgroups().Where(x => model.SubgroupId.Contains(x.Id));

                group.SubGroups.Clear();

                if (model.SubgroupId != null)
                {
                    foreach (var subgroup in subgroups)
                    {
                        group.SubGroups.Add(subgroup);
                    }
                }
                dbContext.SaveChanges();
            }
        }
Exemplo n.º 13
0
        public async Task <IActionResult> UpdateGroupAsync([FromRoute] int groupId, [FromBody] GroupUpdateModel model)
        {
            var currentAccount = await _accountRepository.GetAccountByIdAsync(CurrentAccountId);

            if (currentAccount.GroupId > groupId)
            {
                throw new ForbiddenException(); // the lower the group id, the higher the authority; can only delete the group with authority lower than the current group
            }

            var group = await _groupRepository.GetGroupByIdAsync(groupId);

            if (group == null)
            {
                throw new NotFound404Exception("group");
            }

            if (string.IsNullOrWhiteSpace(model.Name))
            {
                throw new IsRequiredException("name");
            }

            if (model.Name.Length > 50)
            {
                throw new NameIsInvalidException();
            }

            if (await _groupRepository.AnyByNameAsync(model.Name) && !group.Name.Equals(model.Name))
            {
                throw new AlreadyExistsException("name");
            }

            // bind data
            group.Name        = model.Name;
            group.UpdatedDate = DateTime.Now;
            group.UpdatedBy   = CurrentAccountId;

            await _groupRepository.UpdateGroupAsync(group);

            return(Ok(GroupDTO.GetFrom(group)));
        }
Exemplo n.º 14
0
        public async Task <int> UpdateByIdAsync(int groupId, GroupUpdateModel mgroup)
        {
            var group = _context.Groups.FirstOrDefault(c => c.GroupId == groupId);

            if (group == null)
            {
                throw new ExpectException("Could not find data which GroupId equal to " + groupId);
            }
            //If SceneId not null,check whether corresponding Scenes data existed
            if (mgroup.SceneId != null)
            {
                var scene = _context.Scenes.FirstOrDefault(p => p.SceneId == mgroup.SceneId);
                if (scene == null)
                {
                    throw new ExpectException("Could not find Scenes data which SceneId equal to " + mgroup.SceneId);
                }
            }
            //GroupName must be unique
            var checkData = await _context.Groups.Where(g => g.GroupName == mgroup.GroupName &&
                                                        g.GroupId != groupId).ToListAsync();

            if (checkData.Count > 0)
            {
                throw new ExpectException("The data which GroupName equal to '" + mgroup.GroupName + "' already exist in system.");
            }


            //Get UserInfo
            var user = _loginUser.GetLoginUserInfo();

            group.GroupName    = mgroup.GroupName;
            group.SceneId      = mgroup.SceneId;
            group.Modifier     = user.UserName;
            group.ModifiedDate = DateTime.Now;

            await _context.SaveChangesAsync();

            return(group.GroupId);
        }
Exemplo n.º 15
0
        public IActionResult UpdateGroup(GroupUpdateModel group)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var oldGroup = ChatStore.UsersByGroups.Find(x => x.GroupName == group.OldGroup);

            if (oldGroup == null)
            {
                return(NotFound());
            }
            else
            {
                oldGroup.GroupName = group.Group;
                var currentUser = ChatStore.UsersOnline.Find(x => x.Username == User.Identity.Name);
                if (currentUser != null)
                {
                    _chatHubContext.Clients.AllExcept(currentUser.ConnectionId).SendAsync("UpdateGroup", group);
                }
            }
            return(Ok());
        }
 public async Task Put(Guid userId, [FromBody] GroupUpdateModel group)
 {
     await _changeGroupColor.Execute(userId, new Name(group.Name),
                                     new Color(group.Red, group.Green, group.Blue));
 }
Exemplo n.º 17
0
 public async Task <ActionResult <Response> > Update(GroupUpdateModel model)
 {
     return(await _GroupService.Update(model, User));
 }
Exemplo n.º 18
0
 public Task <IResultModel> Update(GroupUpdateModel model)
 {
     return(_service.Update(model));
 }
Exemplo n.º 19
0
 public Task <Group> UpdateAsync(GroupUpdateModel group)
 {
     return(GroupDataAccess.UpdateAsync(group));
 }
Exemplo n.º 20
0
 public Task <Group> CreateAsync(GroupUpdateModel group)
 {
     return(GroupDataAccess.InsertAsync(group));
 }
Exemplo n.º 21
0
        public async Task FullTest()
        {
            var mediator = ServiceProvider.GetService <IMediator>();

            mediator.Should().NotBeNull();

            var createModel = new GroupCreateModel
            {
                Name        = "Group " + DateTime.Now.Ticks,
                Description = "Created from Unit Test",
                TenantId    = Data.Constants.Tenant.Test
            };

            var createCommand = new EntityCreateCommand <GroupCreateModel, GroupReadModel>(MockPrincipal.Default, createModel);
            var createResult  = await mediator.Send(createCommand).ConfigureAwait(false);

            createResult.Should().NotBeNull();

            var identifierQuery  = new EntityIdentifierQuery <Guid, GroupReadModel>(MockPrincipal.Default, createResult.Id);
            var identifierResult = await mediator.Send(identifierQuery).ConfigureAwait(false);

            identifierResult.Should().NotBeNull();
            identifierResult.Name.Should().Be(createModel.Name);


            var entityQuery = new EntityQuery
            {
                Sort = new[] { new EntitySort {
                                   Name = "Updated", Direction = "Descending"
                               } },
                Filter = new EntityFilter {
                    Name = "Name", Value = "Group", Operator = "StartsWith"
                }
            };
            var listQuery = new EntityPagedQuery <GroupReadModel>(MockPrincipal.Default, entityQuery);

            var listResult = await mediator.Send(listQuery).ConfigureAwait(false);

            listResult.Should().NotBeNull();

            var patchModel = new JsonPatchDocument <Group>();

            patchModel.Operations.Add(new Operation <Group>
            {
                op    = "replace",
                path  = "/Description",
                value = "Patch Update"
            });

            var patchCommand = new EntityPatchCommand <Guid, GroupReadModel>(MockPrincipal.Default, createResult.Id, patchModel);
            var patchResult  = await mediator.Send(patchCommand).ConfigureAwait(false);

            patchResult.Should().NotBeNull();
            patchResult.Description.Should().Be("Patch Update");

            var updateModel = new GroupUpdateModel
            {
                Name        = patchResult.Name,
                Description = "Update Command",
                TenantId    = patchResult.TenantId,
                RowVersion  = patchResult.RowVersion
            };

            var updateCommand = new EntityUpdateCommand <Guid, GroupUpdateModel, GroupReadModel>(MockPrincipal.Default, createResult.Id, updateModel);
            var updateResult  = await mediator.Send(updateCommand).ConfigureAwait(false);

            updateResult.Should().NotBeNull();
            updateResult.Description.Should().Be("Update Command");

            var deleteCommand = new EntityDeleteCommand <Guid, GroupReadModel>(MockPrincipal.Default, createResult.Id);
            var deleteResult  = await mediator.Send(deleteCommand).ConfigureAwait(false);

            deleteResult.Should().NotBeNull();
            deleteResult.Id.Should().Be(createResult.Id);
        }