Ejemplo n.º 1
0
        public async Task <OperationStatus <T> > UpdateAsync <T>(T item)
        {
            var dto = item as JobEditDto;
            var job = await _context.Jobs.FirstOrDefaultAsync(x => x.Id == dto.Id);

            if (job == null)
            {
                _operationHelper.BadRequest <T>($"Job {dto.Id} doesn't exist");
            }
            if (dto == null)
            {
                return(_operationHelper.BadRequest <T>("Dto is null"));
            }
            job.Name        = dto.Name;
            job.Description = dto.Description;
            job.Deadline    = dto.Deadline;
            job.StatusId    = dto.JobStatusId;
            try
            {
                _context.Update(job);
                await _context.SaveChangesAsync();

                return(_operationHelper.OK <T>($"Job {job.Id} updated successfully"));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(!JobExists(job)
                    ? _operationHelper.NotFound <T>($"Job {dto.Id} doesn't exist")
                    : _operationHelper.InternalServerError <T>(e.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task <OperationStatus <T> > DeleteByIdAsync <T>(Guid id)
        {
            var user = await _userManager.FindByIdAsync(id.ToString());

            if (user == null)
            {
                return(_operationHelper.NotFound <T>($"user {id} isn't exist"));
            }
            var result = await _userManager.DeleteAsync(user);

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

            return(_operationHelper.OK <T>("User deleted successfully"));
        }
Ejemplo n.º 3
0
        public async Task <OperationStatus <T> > UpdateAsync <T>(T item)
        {
            var dto    = item as StatusDto;
            var status = await _context.Statuses.FindAsync(dto.Id);

            if (status == null)
            {
                _operationHelper.BadRequest <T>($"Status {dto.Id} doesn't exist");
            }
            status.Name  = dto.Name;
            status.Color = dto.Color;
            try
            {
                _context.Update(status);
                await _context.SaveChangesAsync();

                return(_operationHelper.OK <T>($"Status {status.Id} updated successfully"));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(!StatusExists(status.Id) ? _operationHelper.NotFound <T>($"Status {dto.Id} isn't exist")
                    : _operationHelper.InternalServerError <T>(e.Message));
            }
        }