Beispiel #1
0
        public async Task <ServiceResult <int> > CreateAsync(User admin, GroupRequestModel group)
        {
            if (groupsRepository.GetGroupsCount(group.Name) != 0)
            {
                return(ServiceResult <int> .Error(400, "Group already exists"));
            }

            var groupEntity = new Group()
            {
                Name      = group.Name,
                Balance   = 0.0M,
                GroupCode = Math.Abs(group.Name.GetHashCode()).ToString(),
                AdminId   = admin.Id
            };

            var result = await groupsRepository.CreateAsync(groupEntity);

            if (result is null)
            {
                return(ServiceResult <int> .Error(500, "Error creating group"));
            }

            var addedUser = await groupUsersService.AddUser(result.GroupCode, admin);

            if (addedUser is null)
            {
                return(ServiceResult <int> .Error(500, "Error creating adding user to group"));
            }

            result.Admin   = admin;
            result.AdminId = admin.Id;
            return(ServiceResult <int> .Success(GroupViewModel.FromModel(result)));
        }
Beispiel #2
0
        public async Task <ActionResult> Create(GroupModel data)
        {
            try
            {
                await groupsRepository.CreateAsync(new Group
                {
                    Name = data.Name,
                    Year = data.Year
                });

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }