Beispiel #1
0
        public async Task <IActionResult> CreateWorkgroup(WorkgroupDto workgroupDto)
        {
            if (workgroupDto == null)
            {
                throw new ArgumentNullException(Messages.Exception_IncorrectData);
            }

            JsonResult <int> result = await ExecuteActionWithResultAsync(async() =>
                                                                         await _workgroupManager.CreateWorkgroupAsync(workgroupDto)) as JsonResult <int>;

            result.Message = string.Format(Messages.Information_CreateSuccess_Template, Messages.Entity_Workgroup);

            return(result);
        }
Beispiel #2
0
        /// <inheritdoc />
        public async Task <int> CreateWorkgroupAsync(WorkgroupDto workgroupDto)
        {
            Workgroup domainWorkgroup = Mapper.Map <Workgroup>(workgroupDto);

            domainWorkgroup.OwnerId = UserId;
            bool isExist = await _workgroupRepository.IsExistAsync(domainWorkgroup);

            if (isExist)
            {
                throw new CustomException(
                          string.Format(Messages.Exception_EntityAlreadyExist_Templete,
                                        Messages.Entity_Workgroup));
            }

            int result = (await _workgroupRepository.AddAsync(domainWorkgroup)).Id;
            await _workgroupRepository.SaveChangesAsync();

            RoleToWorkgroup roleToWorkgroup = await _workgroupRepository
                                              .AddRoleToWorkgroup(null, domainWorkgroup.Id);

            await _workgroupRepository.SaveChangesAsync();

            return(domainWorkgroup.Id);
        }