public bool SendMeetingRequest(int id) { try { var meeting = _repository.Query().SelectQueryable() .Include(c => c.MeetingAttendances) .Where(c => c.Id == id).FirstOrDefault(); List <NotificationDTO> notifications = new List <NotificationDTO>(); meeting.MeetingAttendances.ToList().ForEach(c => { if (!String.IsNullOrEmpty(c.Email)) { var notication = new NotificationDTO() { Body = "دعوه لحضور إجتماع", DueDate = meeting.MeetingDate, EmployeeId = 0, EmployeeMail = c.Email, IsOpen = false, NotificationType = (int)EnumNotificationType.MeetingRequest, status = (int)EnumMailStatus.Send, Title = "دعوه لحضور إجتماع", MeetingId = meeting.Id, UserId = "" }; notication.Id = _notificationBLL.AddNotification(notication); notifications.Add(notication); } } ); foreach (NotificationDTO notification in notifications) { Mail.SendEmail(_notificationBLL.GetById(notification.Id), "", notification.EmployeeMail); } return(true); } catch (Exception ex) { throw ex; } }
public int Insert(DecisionDTO objDTO, string currentuserId) { Decision decision; objDTO.DecisionExecutions.ToList().ForEach(c => c.DepartmentName = _departmentService.Find(c.DepartmentId).Name); var decId = 0; try { var isValid = !_repository.Query().SelectQueryable().Where(c => c.DecisionNumber == objDTO.DecisionNumber && c.ConferenceYear != 0 && c.ConferenceYear == objDTO.ConferenceYear).Any(); if (isValid) { _unitOfWork.BeginTransaction(); decision = new Decision(); Mapper.Map <DecisionDTO, Decision>(objDTO, decision); if (objDTO.SelectedCompaniesIds != null && objDTO.SelectedCompaniesIds.Any()) { foreach (int company in objDTO.SelectedCompaniesIds) { decision.Companies.Add(_companyRepository.Find(company)); } } base.Insert(decision); if (_unitOfWork.SaveChanges() > 0) { ///decision File var decisionPath = ConfigurationManager.AppSettings["DecisionPath"] + "//" + decision.Id; string fileToCopy = String.Format("{0}//{1}//{2}", ConfigurationManager.AppSettings["TempDecisonPath"], currentuserId, objDTO.DecisionPath.Replace("\"", "")); if (File.Exists(fileToCopy)) { if (!Directory.Exists(decisionPath)) { Directory.CreateDirectory(decisionPath); } File.Copy(fileToCopy, decisionPath + "//" + Path.GetFileName(fileToCopy)); File.Delete(fileToCopy); decision.DecisionPath = String.Format("{0}//{1}", decision.Id, Path.GetFileName(fileToCopy)); } decId = decision.Id; _unitOfWork.SaveChanges(); var attachmentNotRequirdIds = _referenceTypeRepository.Query().SelectQueryable().Where(c => c.IsReferenceDecision).Select(c => c.Id).ToList(); objDTO.ReferenceItems.Where(c => !attachmentNotRequirdIds.Contains(c.ReferenceTypeId)).Where(c => c.Path != "").ToList().ForEach(c => { decision .ReferenceItems .Where(d => d.RefereceItemNo == c.RefereceItemNo).FirstOrDefault() .Path = CopyAttachment( currentuserId, c.Path, decision.Id, decision.ReferenceItems.Where(d => d.RefereceItemNo == c.RefereceItemNo).FirstOrDefault().Id); _unitOfWork.SaveChanges(); }); } foreach (DecisionExecutionDTO execution in objDTO.DecisionExecutions) { List <int> enumForinfoList = new List <int>() { (int)EnumActionType.Inform, (int)EnumActionType.Save, (int)EnumActionType.Review }; var emp = _employeeService.GetByUserId(_departmentCoordinatorRepository.Query().SelectQueryable().Where(c => c.DepartmentId == execution.DepartmentId).FirstOrDefault().UserId); Notification generatedNotification; if (!enumForinfoList.Contains(execution.ActionType)) { generatedNotification = _notificationBLL.AddNotification(emp, null, EnumerationExtension.Description(EnumNotificationType.DecisionExecution), objDTO.Subject, objDTO.ExecutionDate.Value, (int)EnumNotificationType.DecisionExecution); } else { generatedNotification = _notificationBLL.AddNotification(emp, null, EnumerationExtension.Description(EnumNotificationType.DecsionForInform), objDTO.Subject, objDTO.ExecutionDate.Value, (int)EnumNotificationType.DecsionForInform); } generatedNotification.DecisionId = decId; _unitOfWork.SaveChanges(); if (Mail.SendEmail(_notificationBLL.GetById(generatedNotification.Id), EnumerationExtension.Description((EnumActionType)execution.ActionType), emp.Email)) { _notificationBLL.NotificationIsSend(generatedNotification.Id); generatedNotification.DecisionId = decId; _unitOfWork.SaveChanges(); } } _unitOfWork.Commit(); return(decision.Id); } else { throw new ValidationException("dublicate Decision Number"); } } catch (Exception ex) { throw ex; } }