public async Task <IActionResult> UserPhoto(IFormFile file) { { if (string.IsNullOrEmpty(file?.ContentType) || (file.Length == 0)) { return(BadRequest(new ApiError("Image provided is invalid"))); } var size = file.Length; if (size > Convert.ToInt64(Startup.Configuration["MaxImageUploadSize"])) { return(BadRequest(new ApiError("Image size greater than allowed size"))); } using (var memoryStream = new MemoryStream()) { var existingImage = _context.ApplicationUserPhotos.FirstOrDefault(i => i.ApplicationUserId == User.GetUserId()); await file.CopyToAsync(memoryStream); if (existingImage == null) { var userImage = new ApplicationUserPhotos { ContentType = file.ContentType, Content = memoryStream.ToArray(), ApplicationUserId = User.GetUserId() }; _context.ApplicationUserPhotos.Add(userImage); } else { existingImage.ContentType = file.ContentType; existingImage.Content = memoryStream.ToArray(); _context.ApplicationUserPhotos.Update(existingImage); } await _context.SaveChangesAsync(); } return(NoContent()); } }
public async Task <string> SaveAsync() { return(await db.SaveChangesAsync() > 0 ? CleanArchitecture.Constants.Constants.OK : CleanArchitecture.Constants.Constants.Error); }
public async Task SaveParkedCar(string code, string plate, DateTime date) { _context.ParkedCars.Add(new ParkedCar(code, plate, date)); await _context.SaveChangesAsync(); }