Example #1
0
        public async Task <OperationStatus <T> > CreateAsync <T>(T item)
        {
            var dto    = item as RoleDto;
            var result = await _roleManager.CreateAsync(new IdentityRole <Guid>(dto.Name));

            if (!result.Succeeded)
            {
                _operationHelper.InternalServerError <T>(_errorHelper.ErrorMessage(result));
            }
            await _context.SaveChangesAsync();

            return(_operationHelper.OK <T>("Role created successfully"));
        }
        public async Task <OperationStatus <T> > CreateAsync <T>(T item)
        {
            var dto = item as JobCreateDto;

            if (dto == null)
            {
                return(_operationHelper.BadRequest <T>("JobCreateDto is null"));
            }
            var job = new Job()
            {
                Name        = dto.Name,
                Deadline    = dto.Deadline,
                Description = dto.Description,
                StatusId    = dto.StatusId
            };

            try
            {
                await _context.Jobs.AddAsync(job);

                foreach (var userId in dto.SelectedUsers)
                {
                    var user = await _userManager.FindByIdAsync(userId.ToString());

                    _context.UserJobs.Add(new UserJob()
                    {
                        UserId = userId,
                        JobId  = job.Id
                    });
                    await _emailSender.SendEmailAsync(user.Email, "New task for you",
                                                      $"<p>Hello! You have a new task!</p> <p>{job.Name} \n {job.Description}</p>");
                }

                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                return(_operationHelper.InternalServerError <T>(e.Message));
            }
            return(_operationHelper.OK(_mapper.Map <T>(job), "Job created successfully"));
        }
Example #3
0
        public async Task <OperationStatus <T> > CreateAsync <T>(T item)
        {
            var dto = item as StatusDto;

            if (dto == null)
            {
                return(_operationHelper.BadRequest <T>($"StatusDto  is null"));
            }
            var status = new Status()
            {
                Name  = dto.Name,
                Color = dto.Color
            };

            try
            {
                await _context.Statuses.AddAsync(status);

                await _context.SaveChangesAsync();
            }
            catch (Exception e) { return(_operationHelper.InternalServerError <T>(e.Message)); }
            return(_operationHelper.OK <T>("Status created successfully"));
        }
Example #4
0
        public async Task <OperationStatus <T> > CreateAsync <T>(T item)
        {
            if (!(item is EmployeeDto dto))
            {
                return(_operationHelper.BadRequest <T>("EmployeeDto is null"));
            }
            var employee = await _userManager.FindByIdAsync(dto.EmployeeId.ToString());

            employee.ManagerId = dto.UserId;
            var result = await _userManager.UpdateAsync(employee);

            if (!result.Succeeded)
            {
                _operationHelper.InternalServerError <T>(_errorHelper.ErrorMessage(result));
            }
            await _context.SaveChangesAsync();

            return(_operationHelper.OK <T>("Employee added successfully"));
        }
        public async Task <OperationStatus <T> > CreateAsync <T>(T dto)
        {
            var user = _mapper.Map <User>(dto);

            user.UserName = user.Email;
            var result = await _userManager.CreateAsync(user, _defaultPass);

            if (!result.Succeeded)
            {
                _operationHelper.InternalServerError <T>(_errorHelper.ErrorMessage(result));
            }
            await _context.SaveChangesAsync();

            return(_operationHelper.OK <T>("User created successfully"));
        }