public virtual async Task <JsonResult> UpdateContactImage(long contactId) { JsonResult jsonResult; Guid? imageId; try { if (this.Request.Files.Count <= 0 || this.Request.Files[0] == null) { throw new UserFriendlyException(this.L("ContactImage_Change_Error")); } HttpPostedFileBase item = this.Request.Files[0]; if (item.ContentLength > 512000) { throw new UserFriendlyException(this.L("ContactImage_Warn_SizeLimit")); } GetContactForEditOutput contactForEdit = await this._contactAppService.GetContactForEdit(new NullableIdInput <long>(new long?(contactId))); GetContactForEditOutput nullable = contactForEdit; if (nullable.Contact.ImageId.HasValue) { IBinaryObjectManager binaryObjectManager = this._binaryObjectManager; imageId = nullable.Contact.ImageId; await binaryObjectManager.DeleteAsync(imageId.Value); } BinaryObject binaryObject = new BinaryObject(item.InputStream.GetAllBytes()); await this._binaryObjectManager.SaveAsync(binaryObject); nullable.Contact.ImageId = new Guid?(binaryObject.Id); UpdateContactImageInput updateContactImageInput = new UpdateContactImageInput() { ContactId = nullable.Contact.Id.Value }; imageId = nullable.Contact.ImageId; updateContactImageInput.ImageId = new Guid?(imageId.Value); await this._contactAppService.SaveContactImageAsync(updateContactImageInput); jsonResult = this.Json(new MvcAjaxResponse()); } catch (UserFriendlyException userFriendlyException1) { UserFriendlyException userFriendlyException = userFriendlyException1; jsonResult = this.Json(new MvcAjaxResponse(new ErrorInfo(userFriendlyException.Message), false)); } return(jsonResult); }
public async Task SaveContactImageAsync(UpdateContactImageInput input) { Contact async = await this._contactRepository.GetAsync(input.ContactId); Guid?imageId = input.ImageId; if (!imageId.HasValue) { imageId = null; async.ImageId = imageId; } else { imageId = input.ImageId; async.ImageId = new Guid?(imageId.Value); } await this._contactRepository.UpdateAsync(async); }