コード例 #1
0
ファイル: CalcListDto.cs プロジェクト: andreyu/Reports
 public CalcListDto(Document doc)
 {
     id = doc.Id;
     dateCreated = doc.DateCreated;
     beginDate = doc.BeginDate;
     endDate = doc.EndDate;
     if(doc.ReportType == ReportType.CalList)
         number = "За " + CultureInfo.GetCultureInfo("ru-RU").DateTimeFormat.MonthNames[doc.BeginDate.Month - 1].ToLower();
     else
         number = "Cправка от "+ DateCreated.ToString(DateFormat);
     this.comment = string.Empty;
 }
コード例 #2
0
ファイル: EmployeeBl.cs プロジェクト: andreyu/Reports
 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;
 }
コード例 #3
0
ファイル: EmployeeBl.cs プロジェクト: andreyu/Reports
        public bool SaveEditDocumentInternal(EmployeeDocumentEditModel model, UploadFileDto fileDto,
            User owner, out string Error)
        {
            try
            {
                bool isNewDocument = false;
                Error = null;
                List<EmployeeDocumentType> types = GetEmployeeDocumentTypes();
                model.DocumentTypes = types.ConvertAll(x => new IdNameDto(x.Id, x.Name));
                EmployeeDocumentType type = types.Where(x => x.Id == model.DocumentTypeId).First();
                IList<EmployeeDocumentSubType> subTypes = type.SubTypes.OrderBy(x => x.Name).ToList();
                model.DocumentSubTypes = subTypes.ToList().ConvertAll(x => new IdNameDto(x.Id, x.Name));
                Document doc = null;
                if (model.DocumentId != 0)
                {
                    doc = DocumentDao.Load(model.DocumentId);
                    if (model.Version != doc.Version)
                    {
                        model.ReloadPage = true;
                        Error = "Документ был изменен.";
                        return false;
                    }
                    //throw new ModifyDocumentException("Документ был изменен.");
                }
                IUser user = AuthenticationService.CurrentUser;
                if (((user.UserRole & UserRole.Employee) != UserRole.Employee) && (model.DocumentId == 0))
                    throw new ArgumentException("Новый документ может быть создан только сотрудником");
                if ((user.UserRole & UserRole.Employee) == UserRole.Employee)
                {

                    if (user.Id != owner.Id)
                        throw new ArgumentException("Доступ к документу запрещен.");
                    if (doc == null)
                    {
                        doc = new Document {Type = type, User = owner};
                        isNewDocument = true;
                    }
                    if (doc.ManagerDateAccept.HasValue)
                    {
                        model.ReloadPage = true;
                        Error = "Документ уже был одобрен руководителем, его изменение невозможно";
                        return false;
                    }
                    //throw new ModifyDocumentException("Документ уже был одобрен руководителем, его изменение невозможно");
                    Attachment attach;
                    doc = SetDocumentFromModel(model, fileDto, doc, type, subTypes, out attach);
                    model.Date = doc.LastModifiedDate;
                    model.DocumentId = doc.Id;
                    if (attach != null)
                    {
                        model.AttachmentId = attach.Id;
                        model.Attachment = attach.FileName;
                    }
                }
                else if ((user.UserRole & UserRole.Manager) == UserRole.Manager)
                {
                    if (user.Id != owner.Manager.Id)
                        throw new ArgumentException("Доступ к документу запрещен.");
                    if (doc.ManagerDateAccept.HasValue)
                    {
                        Error = "Документ уже был одобрен.";
                        return false;
                    }
                    if (model.IsApprovedByManager)
                    {
                        doc.ManagerDateAccept = DateTime.Now;
                        doc = DocumentDao.MergeAndFlush(doc);
                    }
                }
                else if ((user.UserRole & UserRole.PersonnelManager) == UserRole.PersonnelManager)
                {
                    if (owner.Personnels.Where(x => x.Id == user.Id).FirstOrDefault() == null)
                        throw new ArgumentException("Доступ к документу запрещен.");
                    if (doc.PersonnelManagerDateAccept.HasValue)
                    {
                        Error = "Документ уже был одобрен.";
                        return false;
                    }
                    if (model.IsApprovedByPersonnelManager)
                    {
                        doc.PersonnelManagerDateAccept = DateTime.Now;
                        doc = DocumentDao.MergeAndFlush(doc);
                    }
                }
                else if ((user.UserRole & UserRole.BudgetManager) == UserRole.BudgetManager)
                {
                    //if (user.Id != owner.BudgetManager.Id)
                    //    throw new ArgumentException("Доступ к документу запрещен.");
                    if (doc.BudgetManagerDateAccept.HasValue)
                    {
                        Error = "Документ уже был одобрен.";
                        return false;
                    }
                    if (model.IsApprovedByBudgetManager)
                    {
                        doc.BudgetManagerDateAccept = DateTime.Now;
                        doc = DocumentDao.MergeAndFlush(doc);
                    }
                }
                else if ((user.UserRole & UserRole.OutsourcingManager) == UserRole.OutsourcingManager || (user.UserRole & UserRole.Estimator) == UserRole.Estimator)
                {
                    //if (user.Id != owner.OutsourcingManager.Id)
                    //    throw new ArgumentException("Доступ к документу запрещен.");
                    if (doc.OutsourcingManagerDateAccept.HasValue)
                    {
                        Error = "Документ уже был обработан.";
                        return false;
                    }
                    if (model.IsApprovedByOutsorsingManager)
                    {
                        doc.OutsourcingManagerDateAccept = DateTime.Now;
                        doc = DocumentDao.MergeAndFlush(doc);
                    }
                }
                model.Version = doc.Version;
                if(isNewDocument)
                {
                    Settings settings = SettingsDao.LoadFirst();
                    if(settings == null)
                        Log.Error("Отсутствуют настройки в базе данных.");
                    else if (settings.SendEmailToManagerAboutNew)
                    {
                        if (doc.User.Manager == null || string.IsNullOrEmpty(doc.User.Manager.Email))
                            Log.WarnFormat("У пользователя {0} (Id {1}) отсутствует руководитель или e-mail руководителя не указан.", doc.User.FullName, doc.User.Id);
                        else
                        {
                            SendEmail(settings, model, doc.User.Manager.Email,
                                        "Новая заявка",
                                        string.Format("Пользователем {0} создана новая заявка.", doc.User.FullName));
                            if (!string.IsNullOrEmpty(model.EmailDto.Error))
                                Log.WarnFormat(
                                    "Письмо о новой заявке пользователя {0}(Id {1}) не было отправлено руководителю {2}.Ошибка: {3}",
                                    doc.User.FullName, doc.User.Id, doc.User.Manager.FullName, model.EmailDto.Error);
                        }
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                Log.Error("Error on DocumentEdit:", ex);
                Error = string.Format("Исключение:{0}", ex.GetBaseException().Message);
                return false;
            }
        }