/// <summary> /// This method is responsible for persisting the incoming image into the database. /// </summary> /// <param name="idCompare">Id that the image belongs to</param> /// <param name="model">Instance of a class that contains the base64 encoded string</param> /// <param name="imageSide">Enum value that indicates the image side - ( 0 = Left and 1 = Right )</param> /// <returns></returns> public ValidationResultViewModel AddImage(int idCompare, IncomeImageViewModel model, Constants.ImageSide imageSide) { ValidationResultViewModel modelReturn = new ValidationResultViewModel(); WAESImage item = _waesImageService.GetBySenderIdAndSide(idCompare, (int)imageSide); //I decided to remove the previous record, if exists, to keep comparison clear if (item != null) { Logger.LogInfo("Removing previous '" + SharedMethods.GetEnumDescription(imageSide) + "' image of Id '" + idCompare + "'"); BeginTransaction(); _waesImageService.Remove(item); Commit(); } //Validating if the image content is valid if (SharedMethods.IsBase64Valid(model.Base64Image)) { Logger.LogInfo("Creating new '" + SharedMethods.GetEnumDescription(imageSide) + "' image of Id '" + idCompare + "'"); //Creating the instance of the model to persist on database item = new WAESImage() { IdCompare = idCompare, Side = (int)imageSide }; item.ImageContent = Convert.FromBase64String(model.Base64Image); //Validating the model before persist if (item.IsValid()) { try { BeginTransaction(); _waesImageService.Add(item); Commit(); modelReturn = MountReturn(Constants.PossibleReturns.SUCCESSFULLY_SAVED); modelReturn.Message = String.Format(modelReturn.Message, idCompare); } catch (Exception ex) { modelReturn = MountReturn(Constants.PossibleReturns.ERROR); modelReturn.Message = modelReturn.Message + " : " + ex.Message; } } else { modelReturn = MountReturn(Constants.PossibleReturns.ERROR); } } else { modelReturn = MountReturn(Constants.PossibleReturns.INVALID_BASE64_PARAMETER); } Logger.LogInfo(modelReturn.Message); return(modelReturn); }
public ValidationResultViewModel InputRightmage(int id, IncomeImageViewModel model) { Logger.LogInfo("Trying to input right image of Id = '" + id + "'"); //Calls a service, responsible for manipulate the model and return the model with the result content. return(_manageImagesAppService.AddImage(id, model, Constants.ImageSide.Right)); }