Пример #1
0
        public async Task <bool> UpdateGroup(GroupInputModel model, int groupId, string userId)
        {
            var group = await this.groupRepository.All().FirstOrDefaultAsync(x => x.Id == groupId);

            if (group == null)
            {
                return(false);
            }

            group.Name        = model.Name;
            group.Description = model.Description;

            if (model.CoverImage != null)
            {
                var imageName = Guid.NewGuid().ToString();
                var imageUrl  = await ApplicationCloudinary.UploadImage(this.cloudinary, model.CoverImage, imageName);

                if (!string.IsNullOrEmpty(imageUrl))
                {
                    group.CoverImage = new Image()
                    {
                        Url       = imageUrl,
                        Name      = imageName,
                        CreatorId = userId,
                    };
                }
            }

            this.groupRepository.Update(group);
            await this.groupRepository.SaveChangesAsync();

            return(true);
        }
Пример #2
0
        public async Task UpdateGroupShouldUpdateGroupDescription()
        {
            var db = GetDatabase();
            await db.Groups.AddAsync(new Group()
            {
                Id = 1, Name = "Group007", Description = "Test"
            });

            await db.SaveChangesAsync();

            var groupRepo = new EfDeletableEntityRepository <Group>(db);
            var service   = new GroupService(null, groupRepo, null, null);

            var model = new GroupInputModel()
            {
                Name        = "Group007",
                Description = "Test123",
            };

            var result = await service.UpdateGroup(model, 1, "Test");

            var groupName = db.Groups.FirstOrDefault().Description;

            Assert.Equal("Test123", groupName);
            Assert.NotEqual("Test", groupName);
        }
        public async Task <string> Update(GroupInputModel groupInputModel)
        {
            var model = await _context.Group.FindAsync(groupInputModel.GroupId);

            model.Name = groupInputModel.Name;
            _context.Entry(model).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GroupModelExists(model.GroupId))
                {
                    return("not found");
                }
                else
                {
                    throw;
                }
            }

            return("no content");
        }
Пример #4
0
 public GroupDTO ConvertGroupInputModelToGroupDTO(GroupInputModel group)
 {
     return(new GroupDTO()
     {
         Id = group.Id,
         Name = group.Name,
         StartDate = group.StartDate,
         EndDate = group.EndDate,
     });
 }
Пример #5
0
        public async Task <IActionResult> Create(GroupInputModel inputModel)
        {
            var businessId = this.HttpContext.Items[GlobalConstants.BusinessIdSessionName].ToString();

            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            var groupId = await this.groupService.CreateGroupAsync(businessId, inputModel.Name, inputModel.StandardSalary);

            return(this.RedirectToAction("Index", "People", new { GroupId = groupId }));
        }
Пример #6
0
        public async Task <IActionResult> Create()
        {
            var businessId = this.HttpContext.Items[GlobalConstants.BusinessIdSessionName].ToString();
            var business   = await this.businessService.GetBusinessAsync <BusinessInfoViewModel>(businessId);

            var viewModel = new GroupInputModel()
            {
                BusinessName = business.Name,
                BusinessId   = business.Id,
            };

            return(this.View(viewModel));
        }
        public async Task <IActionResult> PutGroupModel(GroupInputModel groupModel)
        {
            var result = await _groupRepository.Update(groupModel);

            if (result.Equals("no content"))
            {
                return(NoContent());
            }
            else if (result.Equals("not found"))
            {
                return(NotFound());
            }
            else
            {
                return(BadRequest());
            }
        }
Пример #8
0
        public async Task UpdateGroupShouldReturnFalseIfNotGroup()
        {
            var db = GetDatabase();
            await db.Groups.AddAsync(new Group()
            {
                Id = 1, Name = "Group007", Description = "Test"
            });

            await db.SaveChangesAsync();

            var groupRepo = new EfDeletableEntityRepository <Group>(db);
            var service   = new GroupService(null, groupRepo, null, null);

            var model = new GroupInputModel();

            var result = await service.UpdateGroup(model, 2, "Test");

            Assert.False(result);
        }
        public async Task <object> Add(GroupInputModel groupInputModel)
        {
            var model = new GroupModel
            {
                GroupId          = groupInputModel.GroupId,
                Name             = groupInputModel.Name,
                NumberOfStudents = 0
            };

            _context.Group.Add(model);
            try
            {
                await _context.SaveChangesAsync();
            } catch (Exception)
            {
                return("bad request");
            }
            return(model);
        }
Пример #10
0
        public IActionResult PostGroup([FromBody] GroupInputModel groupC)
        {
            if (string.IsNullOrWhiteSpace(groupC.Name))
            {
                return(BadRequest(@"Не заполнено поле ""Название группы"" "));
            }
            Mapper          mapper   = new Mapper();
            GroupDTO        groupDTO = mapper.ConvertGroupInputModelToGroupDTO(groupC);
            AdminDataAccess group    = new AdminDataAccess();
            bool            result   = group.GroupCreate(groupDTO);

            if (result)
            {
                return(Ok("Группа успешно создана"));
            }
            else
            {
                return(BadRequest("Ошибка запроса"));
            }
        }
Пример #11
0
        public ActionResult Create(GroupInputModel model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var group = new Group()
                {
                    Id      = model.Id,
                    Title   = model.Title,
                    OwnerId = model.OwnerId,
                    Type    = model.Type,
                    Website = model.Website
                };

                this.Data.Groups.Add(group);
                this.Data.SaveChanges();

                return(this.RedirectToAction(x => x.SuccessCreate()));
            }

            return(this.View(model));
        }
Пример #12
0
        public async Task <ActionResult <GroupModel> > PostGroup(GroupInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var command = new CreateGroupCommand
            {
                Input = model
            };
            var result = await Mediator.Send(command, HttpContext.RequestAborted)
                         .ConfigureAwait(false);

            if (result.IsFailure)
            {
                return(result.AsActionResult());
            }

            return(CreatedAtAction(nameof(GetGroup), new { id = result.Value.Id }, result.Value));
        }
        public async Task <object> PostGroupModel(GroupInputModel groupModel)
        {
            object result;

            if (await _groupRepository.GetByName(groupModel.Name) == null)
            {
                result = await _groupRepository.Add(groupModel);
            }
            else
            {
                result = "bad request";
            }

            if (result.Equals("bad request"))
            {
                return(BadRequest());
            }
            else
            {
                return(result);
            }
        }
Пример #14
0
        public IActionResult PutGroup([FromBody] GroupInputModel groupU)
        {
            if (string.IsNullOrWhiteSpace(groupU.Name))
            {
                return(BadRequest(@"Не заполнено поле ""Название группы"" "));
            }
            Mapper          mapper   = new Mapper();
            GroupDTO        groupDTO = mapper.ConvertGroupInputModelToGroupDTO(groupU);
            AdminDataAccess adm      = new AdminDataAccess();
            bool            result   = adm.GroupUpdate(groupDTO);

            if (!result)
            {
                return(new BadRequestObjectResult("Запрашиваемой группы не существует"));
            }
            if (result)
            {
                return(Ok("Информация о группе успешно обновлена"));
            }
            else
            {
                return(BadRequest("Ошибка запроса"));
            }
        }