public ContentResult SaveTemplateName(SaveAttacmentModelFromView vModel) { bool saveResult; string error; try { saveResult = true; if (vModel.Name == null || string.IsNullOrEmpty(vModel.Name.Trim())) error = StrNameIsRequired; else if (vModel.Name.Trim().Length > MaxTemplateNameLength) error = string.Format(StrNameIsTooLong, MaxCommentLength); else { var model = new SaveAttacmentModel { EntityId = 0, Id = vModel.Id, EntityTypeId = RequestAttachmentTypeEnum.HelpTemplate, Description = vModel.Name.Trim(), }; saveResult = HelpBl.SaveTemplateName(model); error = model.Error; } } catch (Exception ex) { Log.Error("Exception on SaveAttachment:", ex); error = ex.GetBaseException().Message; saveResult = false; } JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); var jsonString = jsonSerializer.Serialize(new SaveTypeResult { Error = error, Result = saveResult }); return Content(jsonString); }
public ContentResult SaveTemplate(int id, string name, object qqFile) { bool saveResult; string error; try { var length = Request.ContentLength; var bytes = new byte[length]; Request.InputStream.Read(bytes, 0, length); saveResult = true; if (length > MaxFileSize) { error = string.Format(StrInvalidFileSize, MaxFileSize); } else if (name == null || string.IsNullOrEmpty(name.Trim())) { error = StrNameIsRequired; } else if (name.Trim().Length > MaxTemplateNameLength) { error = string.Format(StrNameIsTooLong, MaxCommentLength); } else { byte[] context; string fileName = MissionOrderController.GetFileName(qqFile, out context); if (context != null) bytes = context; var model = new SaveAttacmentModel { EntityId = 0, Id = id, EntityTypeId = RequestAttachmentTypeEnum.HelpTemplate, Description = name.Trim(), FileDto = new UploadFileDto { Context = bytes, FileName = fileName, //ContextType = Request.Content, } }; saveResult = HelpBl.SaveTemplate(model); error = model.Error; } } catch (Exception ex) { Log.Error("Exception on SaveAttachment:", ex); error = ex.GetBaseException().Message; saveResult = false; } JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); var jsonString = jsonSerializer.Serialize(new SaveTypeResult { Error = error, Result = saveResult }); return Content(jsonString); }
public ContentResult SaveAttachment(int id,int type, string description, object qqFile) { bool saveResult; string error; try { var length = Request.ContentLength; var bytes = new byte[length]; Request.InputStream.Read(bytes, 0, length); saveResult = true; if (length > MaxFileSize) { error = string.Format("Размер прикрепленного файла > {0} байт.", MaxFileSize); } else if (description == null || string.IsNullOrEmpty(description.Trim())) { error = "Описание - обязательное поле"; } else if (description.Trim().Length > MaxCommentLength) { error = string.Format("Длина поля 'Описание' не может превышать {0} символов.", MaxCommentLength); } else { byte[] context; string fileName = MissionOrderController.GetFileName(qqFile, out context); if (context != null) bytes = context; var model = new SaveAttacmentModel { EntityId = id, EntityTypeId = (RequestAttachmentTypeEnum)type, Description = description.Trim(), FileDto = new UploadFileDto { Context = bytes, FileName = fileName, } }; saveResult = RequestBl.SaveAttachment(model); error = model.Error; } } catch (Exception ex) { Log.Error("Exception on SaveAttachment:", ex); error = ex.GetBaseException().Message; saveResult = false; } JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); var jsonString = jsonSerializer.Serialize(new SaveTypeResult { Error = error, Result = saveResult }); return Content(jsonString); }
public bool SaveTemplateName(SaveAttacmentModel model) { if (AuthenticationService.CurrentUser.UserRole != UserRole.Admin) { model.Error = StrCannotEditFaq; return false; } RequestAttachment attach = RequestAttachmentDao.Load(model.Id); attach.DateCreated = DateTime.Now; attach.Description = model.Description; attach.CreatorRole = RoleDao.Load((int)CurrentUser.UserRole); RequestAttachmentDao.SaveFileNotChangeAndFlush(attach); return true; }
public bool SaveTemplate(SaveAttacmentModel model) { if (AuthenticationService.CurrentUser.UserRole != UserRole.Admin) { model.Error = StrCannotEditFaq; return false; } RequestAttachment attach; if (model.Id == 0) { attach = new RequestAttachment { ContextType = RequestBl.GetFileContext(model.FileDto.FileName), DateCreated = DateTime.Now, Description = model.Description, FileName = model.FileDto.FileName, RequestId = 0, RequestType = (int) model.EntityTypeId, UncompressContext = model.FileDto.Context, CreatorRole = RoleDao.Load((int) CurrentUser.UserRole) }; } else { attach = RequestAttachmentDao.Load(model.Id); attach.ContextType = RequestBl.GetFileContext(model.FileDto.FileName); attach.DateCreated = DateTime.Now; attach.Description = model.Description; attach.FileName = model.FileDto.FileName; attach.UncompressContext = model.FileDto.Context; attach.CreatorRole = RoleDao.Load((int) CurrentUser.UserRole); } RequestAttachmentDao.SaveAndFlush(attach); model.Id = attach.Id; return true; }
public ContentResult SaveCostAttachment(int id,object qqFile) { bool saveResult; string error; int resultId = 0; try { var length = Request.ContentLength; var bytes = new byte[length]; Request.InputStream.Read(bytes, 0, length); saveResult = true; if (length > MaxFileSize) error = string.Format("Размер прикрепленного файла > {0} байт.", MaxFileSize); else { byte[] context; string fileName = GetFileName(qqFile, out context); if (context != null) bytes = context; var model = new SaveAttacmentModel { EntityId = id, EntityTypeId = RequestAttachmentTypeEnum.MissionReportCost, Description = string.Empty, FileDto = new UploadFileDto { Context = bytes, FileName = fileName, //ContextType = Request.Content, } }; saveResult = RequestBl.SaveUniqueAttachment(model); error = model.Error; resultId = model.Id; } } catch (Exception ex) { Log.Error("Exception on SaveCostAttachment:", ex); error = ex.GetBaseException().Message; saveResult = false; } JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); var jsonString = jsonSerializer.Serialize(new SaveTypeResult { Error = error, Result = saveResult,Id = resultId }); return Content(jsonString); }