public void Execute(CategoryDto request) { _validator.ValidateAndThrow(request); var newCategory = new Category { CategoryName = request.CategoryName }; _context.Add(newCategory); _context.SaveChanges(); }
public void Execute(LocationUpdateDto request) { var location = _context.Locations.Find(request.Id); if (location == null) { throw new EntityNotFoundException(request.Id, typeof(Location)); } location.CityName = request.CityName; _context.SaveChanges(); }
public void Execute(CategoryDto request) { _validator.ValidateAndThrow(request); var category = _context.Categories.Find(request.Id); if (category == null) { throw new EntityNotFoundException(request.Id, typeof(Category)); } category.CategoryName = request.CategoryName; _context.SaveChanges(); }
public void Execute(LocationDto request) { validations.ValidateAndThrow(request); var location = new Location { CityName = request.CityName }; _context.Add(location); _context.SaveChanges(); }
public void Execute(int request) { var jobuser = _context.JobUsers.Find(request); if (jobuser == null) { throw new EntityNotFoundException(request, typeof(Domain.JobUser)); } jobuser.IsDeleted = true; jobuser.IsActive = false; jobuser.DeletedAt = DateTime.Now; _context.SaveChanges(); }
public void Execute(ChangePasswordDto request) { _validator.ValidateAndThrow(request); var user = _context.Users.Find(request.UserId); if (user == null || user.Password != request.OldPassword) { throw new EntityNotFoundException(request.UserId, typeof(Domain.User)); } user.Password = request.NewPassword; _context.SaveChanges(); }
public void Execute(RegisterDto request) { _validation.ValidateAndThrow(request); var newFileName = "basicavatar.jpg"; if (request.Avatar != null) { var guid = Guid.NewGuid(); var extension = Path.GetExtension(request.Avatar.FileName); newFileName = guid + extension; var path = Path.Combine("wwwroot", "images", newFileName); using (var fileStream = new FileStream(path, FileMode.Create)) { request.Avatar.CopyTo(fileStream); } } var newFileNameCv = ""; if (request.Cv != null) { var guidCv = Guid.NewGuid(); newFileNameCv = guidCv + request.Cv.FileName; var pathCv = Path.Combine("wwwroot", "cv", newFileNameCv); using (var fileStreamCv = new FileStream(pathCv, FileMode.Create)) { request.Cv.CopyTo(fileStreamCv); } } var registration = new User { Username = request.Username, Password = request.Password, Name = request.Name, Surname = request.Surname, Email = request.Email, Phone = request.Phone, Birthdate = request.Birthdate, CvPath = newFileNameCv, AvatarPath = newFileName, AvatarAlt = request.AvatarAlt, RoleId = request.RoleId }; _context.Add(registration); _context.SaveChanges(); }
public void Execute(int request) { var location = _context.Locations.Find(request); if (location == null) { throw new EntityNotFoundException(request, typeof(Location)); } location.IsDeleted = true; location.IsActive = false; location.DeletedAt = DateTime.Now; _context.SaveChanges(); }
public void Execute(int request) { var category = _context.Categories.Find(request); if (category == null) { throw new EntityNotFoundException(request, typeof(Category)); } category.IsDeleted = true; category.IsActive = false; category.DeletedAt = DateTime.Now; _context.SaveChanges(); }
public void Execute(JobvacanciesDto request) { _validator.ValidateAndThrow(request); var newJobVacancie = new JobUser { JobId = request.JobId, UserId = _actor.Id, Status = 0, JobName = request.JobName, JobDescription = request.JobDescription }; _context.Add(newJobVacancie); _context.SaveChanges(); }
public void Execute(JobvacanciesDto request) { _validator.ValidateAndThrow(request); var jobuser = _context.JobUsers.Find(request.Id); if (jobuser == null) { throw new EntityNotFoundException((int)request.Id, typeof(Domain.JobUser)); } jobuser.Status = (Status)request.Status; _context.SaveChanges(); }
public void Execute(int request) { var jobvac = _context.JobUsers.Find(request); if (jobvac == null || jobvac.UserId != _actor.Id) { throw new EntityNotFoundException(request, typeof(Category)); } jobvac.IsDeleted = true; jobvac.IsActive = false; jobvac.DeletedAt = DateTime.Now; _context.SaveChanges(); }
public void Execute(UserInfoUpdateDto request) { _validator.ValidateAndThrow(request); var user = _context.Users.Find(request.UserId); if (user == null) { throw new EntityNotFoundException(request.UserId, typeof(User)); } var newFileName = user.AvatarPath; if (request.Avatar != null) { var guid = Guid.NewGuid(); var extension = Path.GetExtension(request.Avatar.FileName); newFileName = guid + extension; var path = Path.Combine("wwwroot", "images", newFileName); using (var fileStream = new FileStream(path, FileMode.Create)) { request.Avatar.CopyTo(fileStream); } } var newFileNameCv = user.CvPath; if (request.Cv != null) { var guidCv = Guid.NewGuid(); newFileNameCv = guidCv + request.Cv.FileName; var pathCv = Path.Combine("wwwroot", "cv", newFileNameCv); using (var fileStreamCv = new FileStream(pathCv, FileMode.Create)) { request.Cv.CopyTo(fileStreamCv); } } user.Username = request.Username; user.Name = request.Name; user.Surname = request.Surname; user.Phone = request.Phone; user.Birthdate = request.Birthdate; user.AvatarAlt = request.AvatarAlt; user.AvatarPath = newFileName; user.CvPath = newFileNameCv; _context.SaveChanges(); }
public void Execute(JobUpdate request) { _validation.ValidateAndThrow(request.Dto); var job = _context.Jobs .Include(j => j.JobCategories).ThenInclude(c => c.Category) .Include(j => j.JobLocations).ThenInclude(l => l.Location) .FirstOrDefault(j => j.Id == request.Id); if (job == null) { throw new EntityNotFoundException(request.Id, typeof(Domain.Job)); } job.JobName = request.Dto.JobName; job.JobResponsibilities = request.Dto.JobResponsibilities; job.JobRequirments = request.Dto.JobRequirments; job.JobDescription = request.Dto.JobDescription; job.WorktimeId = (Worktime)request.Dto.WorktimeId; job.WorktimeDescription = request.Dto.WorktimeDescription; job.PaymentId = (Payment)request.Dto.PaymentId; job.PaymentDescription = request.Dto.PaymentDescription; job.EndDate = request.Dto.EndDate; job.IsFeatured = request.Dto.IsFeatured; job.IsPremium = request.Dto.IsPremium; job.JobCategories.Clear(); foreach (var category in request.Dto.Categories) { job.JobCategories.Add(new JobCategory { CategoryId = category.Id }); } job.JobLocations.Clear(); foreach (var location in request.Dto.Locations) { job.JobLocations.Add(new JobLocation { LocationId = location.Id, DetailedLocation = location.DetailedLocation }); } _context.SaveChanges(); }
public void Log(UseCase userCase, IAppActor actor, object data) { int?userid; if (actor.Id != 0) { userid = actor.Id; } else { userid = null; } _context.UseCaseLoggers.Add(new Domain.UseCaseLogger { UseCaseDatetime = DateTime.Now, UserId = userid, UseCaseName = userCase.Name, Data = JsonConvert.SerializeObject(data) }); _context.SaveChanges(); }
public void Execute(JobDto request) { _validation.ValidateAndThrow(request); var job = new Job { JobName = request.JobName, JobResponsibilities = request.JobResponsibilities, JobRequirments = request.JobRequirments, JobDescription = request.JobDescription, WorktimeId = (Worktime)request.WorktimeId, WorktimeDescription = request.WorktimeDescription, PaymentId = (Payment)request.PaymentId, PaymentDescription = request.PaymentDescription, EndDate = request.EndDate, IsFeatured = request.IsFeatured, IsPremium = request.IsPremium }; foreach (var category in request.Categories) { job.JobCategories.Add(new JobCategory { CategoryId = category.Id }); } foreach (var location in request.Locations) { job.JobLocations.Add(new JobLocation { LocationId = location.Id, DetailedLocation = location.DetailedLocation }); } _context.Add(job); _context.SaveChanges(); }