public ContentResult SendToBilling(int documentId) { bool saveResult; string error; try { var model = new SendToBillingModel { DocumentId = documentId, }; saveResult = EmployeeBl.SendToBilling(model); error = model.Error; } catch (Exception ex) { Log.Error("Exception on SendToBilling:", 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 SendToBilling(SendToBillingModel model) { try { IUser user = AuthenticationService.CurrentUser; if ((user.UserRole & UserRole.OutsourcingManager) != UserRole.OutsourcingManager || (user.UserRole & UserRole.Estimator) != UserRole.Estimator) { model.Error = "Действие недоступно для данной роли."; return false; } User current = UserDao.Load(user.Id); Document doc = DocumentDao.Load(model.DocumentId); if (!doc.OutsourcingManagerDateAccept.HasValue) { model.Error = "Заявка не была обработана."; return false; } string email = string.IsNullOrEmpty(current.Email) ? null : current.Email; SendEmailToBilling(model,email, string.Format("Заявка {0} {1}", doc.Type.Name, doc.SubType.Name), string.Format("Пользователь {0} (код 1С {1}) <br>Текст: {2} <br>Дата заявки: {3}" ,doc.User.FullName,doc.User.Code ,doc.Comment,doc.LastModifiedDate)); if (!string.IsNullOrEmpty(model.EmailDto.Error)) { model.Error = model.EmailDto.Error; return false; } doc.SendEmailToBilling = true; DocumentDao.MergeAndFlush(doc); return true; } catch (Exception ex) { Log.Error("Exception", ex); model.Error = "Исключение: " + ex.GetBaseException().Message; return false; } }