public override string ToString() { string result = Commnad.ToString(); foreach (var item in Args) { result += "|" + item; } return(result); }
public async Task <Result <Unit> > Handle(Commnad request, CancellationToken cancellationToken) { if (request.Profile.Photofile == null) { var profile = await _context.Profiles.FindAsync(request.Profile.Id); if (profile == null) { return(null); } _mapper.Map(request.Profile, profile); } else { var profile = await _context.Profiles.Include(p => p.Photo).Where(exp => exp.Id == request.Profile.Id).FirstOrDefaultAsync <MyProfile>(); if (profile == null) { return(null); } var removePhoto = await _photoAccessor.DeletePhoto(profile.Photo.Id); if (removePhoto == null) { return(Result <Unit> .Failure("Failed to delete photo")); } _context.Remove(profile.Photo); var photoResult = await _photoAccessor.AddPhoto(request.Profile.Photofile); if (photoResult == null) { return(Result <Unit> .Failure("Failed to upload photo")); } var photo = new Photo { Id = photoResult.PublicId, Url = photoResult.Url, IsMain = true }; request.Profile.Photo = photo; _mapper.Map(request.Profile, profile); } var result = await _context.SaveChangesAsync() > 0; if (!result) { return(Result <Unit> .Failure("Failed to Edit Data")); } return(Result <Unit> .Success(Unit.Value)); }
public async Task <Result <Unit> > Handle(Commnad request, CancellationToken cancellationToken) { var data = await _context.Schools.Include(e => e.Logo).Where(e => e.Id == request.Education.Id).FirstOrDefaultAsync(); if (data == null) { return(null); } if (request.Education.PhotoFile != null) { if (data.Logo != null) { var res = await _photoAccessor.DeletePhoto(data.Logo.Id); if (res == null) { return(Result <Unit> .Failure("Failed to delete photo")); } } var newPhoto = await _photoAccessor.AddPhoto(request.Education.PhotoFile); if (newPhoto == null) { return(Result <Unit> .Failure("Failed to upload new photo")); } var photo = new Photo { IsMain = true, Id = newPhoto.PublicId, Url = newPhoto.Url }; request.Education.Logo = photo; } else { request.Education.Logo = data.Logo; } _mapper.Map(request.Education, data); var result = await _context.SaveChangesAsync() > 0; if (!result) { return(Result <Unit> .Failure("Failed to Edit Data")); } return(Result <Unit> .Success(Unit.Value)); }
public async Task <Result <Unit> > Handle(Commnad request, CancellationToken cancellationToken) { var experience = await _context.Experiences .Where(e => e.Id == request.Experience.Id) .Include(e => e.Logo).FirstOrDefaultAsync(); if (experience == null) { return(null); } if (request.Experience.PhotoFile != null) { var removePhoto = await _photoAccessor.DeletePhoto(experience.Logo.Id); if (removePhoto == null) { return(Result <Unit> .Failure("Failed to delete photo")); } _context.Photos.Remove(experience.Logo); var photoResult = await _photoAccessor.AddPhoto(request.Experience.PhotoFile); if (photoResult == null) { return(Result <Unit> .Failure("Failed to upload photo")); } var photo = new Photo { Id = photoResult.PublicId, Url = photoResult.Url, IsMain = true }; request.Experience.Logo = photo; } else { request.Experience.Logo = experience.Logo; } _mapper.Map(request.Experience, experience); var result = await _context.SaveChangesAsync() > 0; if (!result) { return(Result <Unit> .Failure("Failed to Edit Data")); } return(Result <Unit> .Success(Unit.Value)); }