public async Task <Request> saveRequest(RequestViewModel requestVM, int UserID) { checkBissines(requestVM, UserID, "insert"); requestVM.request.RequestID = 0; await _context.Requests.AddAsync(requestVM.request); // await this._factory.requestRepository.AddAsyn(requestVM.request); foreach (RequestStage stage in requestVM.RequestStages) { stage.RequestID = requestVM.request.RequestID; stage.ActionCode = "COR01"; stage.OrderStageID = 0; } foreach (RequestExtraField obj in requestVM.RequestExtraFields) { obj.RequestID = requestVM.request.RequestID; obj.RequestExtraFieldID = 0; } await _context.AddRangeAsync(requestVM.RequestStages); if (requestVM.RequestExtraFields != null) { await _context.AddRangeAsync(requestVM.RequestExtraFields); } await _context.SaveChangesAsync(); if (requestVM.attachments != null) { foreach (Attachment dtl in requestVM.attachments) { Attachment obj = _context.Attachments.FirstOrDefault(p => p.AttachmentID == dtl.AttachmentID); obj.ReferenceID = requestVM.request.RequestID; await attachmentConcrete.UpdateAttachment(obj); } } List <NextStageVM> nextStageVMs = await GetNextStageInfo(requestVM.request.RequestID, UserID); if (nextStageVMs != null) { var emp = employeesConcrete.FindBy(p => p.EmployeeID == requestVM.request.EmployeeID).SingleOrDefault(); var type = requestTypeConcrete.FindBy(p => p.RequestTypeID == requestVM.request.RequestTypeID).SingleOrDefault(); foreach (NextStageVM item in nextStageVMs) { if (item.UserId != null) { await notificationConcrete.SaveNotification(requestVM.request.RequestID, false, "NOT01", Convert.ToInt32(item.UserId), 0, UserID); await emails.InsertEmailsNotifications($" New Request طلب جديد {type.RequestNameAr}", $"يوجد طلب جديد برقم {requestVM.request.RequsetPrivateNumber} للموظف {emp.ArabicName}", null, Convert.ToInt32(item.UserId), requestVM.request.RequestID, false); } } } return(requestVM.request); }
public async Task <Evaluation> saveEvaluation(EvaluationViewModel evaluationVM, int UserID) { checkBissines(evaluationVM, UserID, "Insert"); Evaluation evaluation = new Evaluation() { EvaluationID = 0, EvalCharterID = evaluationVM.evaluationVM.EvalCharterID, EmployeeID = evaluationVM.evaluationVM.EmployeeID, UserID = evaluationVM.evaluationVM.UserID, Notes = evaluationVM.evaluationVM.Notes }; await _context.Evaluations.AddAsync(evaluation); evaluationVM.evaluationCharterItems = new List <EvaluationCharterItem>(); foreach (EvalCharterCommunityViewModel obj in evaluationVM.evalCharterCommunityItemsVM) { EvaluationCharterItem item = new EvaluationCharterItem { EvaluationCharterItemsID = 0, EvaluationID = evaluation.EvaluationID, EvalCharterDetailsItemsID = obj.EvalCharterDetailsItemsID, DegreeEmployee = Convert.ToInt16(obj.DegreeEmployee) }; evaluationVM.evaluationCharterItems.Add(item); } await _context.AddRangeAsync(evaluationVM.evaluationCharterItems); await _context.SaveChangesAsync(); AttachmentConcrete attachmentConcrete = new AttachmentConcrete(_context, _configuration); if (evaluationVM.attachments != null) { foreach (Attachment dtl in evaluationVM.attachments) { Attachment obj = _context.Attachments.FirstOrDefault(p => p.AttachmentID == dtl.AttachmentID); obj.ReferenceID = evaluation.EvaluationID; await attachmentConcrete.UpdateAttachment(obj); } } Employee employeeManager = _context.EmployeeInfoView.Where(p => p.ManagerID == evaluationVM.evaluationVM.EmployeeID).FirstOrDefault(); Users usersManager = _context.Users.Where(p => p.EmployeeId == employeeManager.EmployeeID).FirstOrDefault(); if (usersManager != null) { await notificationConcrete.SaveNotification(evaluation.EvaluationID, false, "NOT02", usersManager.UserId, 0, UserID); } return(evaluation); }