public bool SaveType(EditTypeModel model) { try { if (!ValidateModel(model)) return false; var type = new EmployeeDocumentType(); if (model.Id > 0) type = EmployeeDocumentTypeDao.Load(model.Id); type.Name = model.Name.Trim(); EmployeeDocumentTypeDao.MergeAndFlush(type); return true; } catch (Exception ex) { Log.Error("Exception", ex); model.Error = "Исключение: " + ex.GetBaseException().Message; return false; } }
protected Document SetDocumentFromModel(EmployeeDocumentEditModel model, UploadFileDto fileDto, Document doc, EmployeeDocumentType type, IList<EmployeeDocumentSubType> subTypes, out Attachment attach) { doc.Comment = model.EditComment; doc.LastModifiedDate = DateTime.Now; doc.Type = type; doc.SubType = subTypes.Where(x => x.Id == model.DocumentSubTypeId).FirstOrDefault(); doc = DocumentDao.MergeAndFlush(doc); attach = null; if (model.DocumentId != 0) attach = AttachmentDao.FindByDocumentId(doc.Id); if (fileDto != null) { if (attach == null) attach = new Attachment(); attach.Context = fileDto.Context; attach.ContextType = fileDto.ContextType; attach.FileName = fileDto.FileName; attach.Document = doc; AttachmentDao.SaveAndFlush(attach); } return doc; }