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(); }
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(); }
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" }); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }