public IServiceResults<Guid> Add(IeltsMaterial model) { _IeltsMaterial.Add(model); var result = _uow.SaveChanges(); return new ServiceResults<Guid>() { IsSuccessfull = result.ToBool(), Message = result.ToMessage(BusinessMessage.Error), Result = model.IeltsMaterialId }; }
public virtual ActionResult SendWrittingFile(IeltsMaterial model, HttpPostedFileBase file) { model.IeltsMaterialId = Guid.NewGuid(); if (!ModelState.IsValid) { SetDropDownlist(); return View(model); } if (file == null) { SetDropDownlist(); ModelState.AddModelError(nameof(model.File), LocalMessage.PleaseSelectFile); return View(model); } model.Rebind(); #region SaveFile byte[] fileData = null; using (var binaryReader = new BinaryReader(file.InputStream)) { fileData = binaryReader.ReadBytes(file.ContentLength); } var url = _filesProxyAdapter.UploadDocument(new PostedFile { Content = fileData, FileName = $"{model.IeltsMaterialId}.{file.FileName.Split('.')[1]}" }); if (string.IsNullOrEmpty(url.DirectLink)) { SetDropDownlist(); ModelState.AddModelError(nameof(model.File), LocalMessage.Error); return View(model); } #endregion #region SaveRecord model.File = url.DirectLink; model.Path = url.Extension; var insertResult = _ieltsMaterialService.Add(model); if (!insertResult.IsSuccessfull) { this.NotificationController().Notify(insertResult.Message, NotificationStatus.Error); _filesProxyAdapter.Delete(url.Extension); } #endregion return RedirectToAction(MVC.IELTS.ActionNames.SendWrittingFile, MVC.IELTS.Name); }