Ejemplo n.º 1
0
        public void Execute(UserDto request)
        {
            _validator.ValidateAndThrow(request);
            var exisitingRoles = _context.UserRoles.Where(o => o.UserId == request.Id).ToList();

            foreach (var item in exisitingRoles)
            {
                _context.Entry(item).State = EntityState.Deleted;
            }
            var user = new Users()
            {
                Id        = request.Id,
                FirstName = request.FirstName,
                LastName  = request.LastName,
                UserName  = request.UserName,
                Password  = request.Password,
                Email     = request.Email
            };
            var model = new UserRoles()
            {
                RoleId = request.RoleId,
                UserId = user.Id
            };

            user.UserRoles.Add(model);
            _context.Entry(model).State = EntityState.Added;
            _context.Entry(user).State  = user.Id > 0 ? EntityState.Modified : EntityState.Added;
            _context.SaveChanges();
        }
Ejemplo n.º 2
0
        public void Execute(RoleDto request)
        {
            _validator.ValidateAndThrow(request); //ValidationException
            var exisitingPermissions = _context.RolePermissions.Where(o => o.RoleId == request.Id).ToList();

            foreach (var item in exisitingPermissions)
            {
                _context.Entry(item).State = EntityState.Deleted;
            }
            var role = new Roles()
            {
                Id       = request.Id,
                RoleName = request.RoleName
            };

            foreach (var item in request.PerimissionIds)
            {
                var rolePermission = new RolePermissions()
                {
                    PermissionId = item,
                    RoleId       = request.Id
                };
                _context.Entry(rolePermission).State = EntityState.Added;
            }
            _context.Entry(role).State = EntityState.Modified;

            _context.SaveChanges();
        }
Ejemplo n.º 3
0
        public void Execute(RegisterUserDto request)
        {
            _validator.ValidateAndThrow(request);
            var user = new Users()
            {
                FirstName = request.FirstName,
                LastName  = request.LastName,
                UserName  = request.UserName,
                Password  = request.Password,
                Email     = request.Email
            };
            var model = new UserRoles()
            {
                RoleId = request.RoleId,
                UserId = user.Id
            };

            user.UserRoles.Add(model);
            _context.Entry(model).State = EntityState.Added;
            _context.Entry(user).State  = user.Id > 0 ? EntityState.Modified : EntityState.Added;
            _context.SaveChanges();
            _sender.Send(new SendEmailDto
            {
                Content = "<h1>Successfull registration!</h1>",
                SendTo  = request.Email,
                Subject = "Registration"
            });
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PutCustomer(int id, Customer customer)
        {
            if (id != customer.CustomerID)
            {
                return(BadRequest());
            }

            _context.Entry(customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 5
0
        public void Execute(JobDto request)
        {
            _validator.ValidateAndThrow(request); //ValidationException

            var job = new Jobs
            {
                CustomerId      = request.CustomerId,
                Deposit         = request.Deposit,
                JobStatusId     = 1,
                JobTypeId       = request.JobTypeId,
                MinimumHours    = request.MinimumHours,
                MoveDate        = request.MoveDate,
                NumberOfMovers  = request.NumberOfMovers,
                NumberOfTrucks  = request.NumberOfTrucks,
                CreatedByUserId = request.CreatedByUserId,
                PricePerHour    = request.PricePerHour,
                Pickup          = false,
                Delivery        = false,
                Id = request.Id
            };

            _context.Entry(job).State = job.Id > 0 ? EntityState.Modified : EntityState.Added;

            _context.SaveChanges();
        }
Ejemplo n.º 6
0
        public void Execute(JobReviewDto request)
        {
            _validator.ValidateAndThrow(request); //ValidationException
            var jobReview = new JobReviews()
            {
                Description = request.Description,
                JobId       = request.JobId,
                UserId      = request.UserId
            };

            _context.Entry(jobReview).State = EntityState.Added;
            _context.SaveChanges();
        }
Ejemplo n.º 7
0
        public void Execute(RoleDto request)
        {
            _validator.ValidateAndThrow(request); //ValidationException
            var role = new Roles()
            {
                Id       = request.Id,
                RoleName = request.RoleName
            };

            foreach (var item in request.PerimissionIds)
            {
                var rolePermission = new RolePermissions()
                {
                    PermissionId = item,
                    RoleId       = request.Id
                };
                _context.Entry(rolePermission).State = EntityState.Added;
            }
            _context.Entry(role).State = EntityState.Added;

            _context.SaveChanges();
        }
Ejemplo n.º 8
0
        public void Execute(int request)
        {
            var jobReview = _context.JobReviews.Find(request);

            if (jobReview == null)
            {
                throw new EntityNotFoundException(request, typeof(JobReviews));
            }
            jobReview.IsDeleted             = true;
            _context.Entry(jobReview).State = EntityState.Modified;

            _context.SaveChanges();
        }
Ejemplo n.º 9
0
        public void Execute(int request)
        {
            var customer = _context.Customers.Find(request);

            if (customer == null)
            {
                throw new EntityNotFoundException(request, typeof(Customers));
            }

            customer.IsDeleted             = true;
            _context.Entry(customer).State = EntityState.Modified;

            _context.SaveChanges();
        }
Ejemplo n.º 10
0
        public void Execute(JobImageDto request)
        {
            _validator.ValidateAndThrow(request); //ValidationException

            var jobImage = new JobImages
            {
                ImagePath = request.ImagePath,
                JobId     = request.JobId
            };

            _context.Entry(jobImage).State = jobImage.Id > 0 ? EntityState.Modified : EntityState.Added;

            _context.SaveChanges();
        }
Ejemplo n.º 11
0
        public void Execute(CustomerDto request)
        {
            _validator.ValidateAndThrow(request); //ValidationException

            var customer = new Customers
            {
                FirstName = request.FirstName,
                Email     = request.Email,
                LastName  = request.LastName,
                Phone     = request.Phone,
                Id        = request.Id
            };

            _context.Entry(customer).State = customer.Id > 0 ? EntityState.Modified : EntityState.Added;

            _context.SaveChanges();
        }