public DecisionDTO GetById(int id, string currentUser) { try { DecisionDTO decision = new DecisionDTO(); var ListOfDepId = _departmentCoordinatorRepository.Query().SelectQueryable().Where(c => c.UserId == currentUser).Select(c => c.DepartmentId).ToList(); Mapper.Map <Decision, DecisionDTO>(_repository .Query() .Include(c => c.Country) .Include(c => c.ActivitySectors) .Include(c => c.Companies) .Include(c => c.AgendaItem) .Include(c => c.AgendaDetail) .Include(c => c.Departments) .Include(c => c.ReferenceItems.Select(d => d.ReferenceType)) .Include(c => c.ReferenceItems.Select(d => d.ReferenceDecision)) .Include(c => c.DecisionExecutions.Select(d => d.Attachments)) .Include(c => c.SubCategory.MainCategory.CouncilType) .SelectQueryable() .Where(c => c.Id == id).FirstOrDefault(), decision); decision.KeyWordList = !String.IsNullOrEmpty(decision.KeyWords) ? decision.KeyWords.Split(' ').ToList() : null; decision.DecisionExecutions.ToList().ForEach(c => c.NeedAction = ListOfDepId.Contains(c.DepartmentId) && c.ExecutionDate == null); return(decision); } catch (Exception ex) { throw ex; } }
/// <inheritdoc /> public async Task ChangeDecisionAsync(DecisionDTO decisionDto) { Decesion decision = await _repoWrapper.Decesion.GetFirstAsync(x => x.ID == decisionDto.ID); decision.Name = decisionDto.Name; decision.Description = decisionDto.Description; _repoWrapper.Decesion.Update(decision); await _repoWrapper.SaveAsync(); }
public DecisionDTO Create(DecisionDTO dto) { // Mapeamos el dto a la entidad, la añadimos al contexto, guardamos y devolvemos el dto mapeado var model = _mapper.Map <Decision>(dto); _context.Decisiones.Add(model); _context.SaveChanges(); return(_mapper.Map <DecisionDTO>(model)); }
public async Task <IActionResult> Update(int id, DecisionDTO decision) { if (id != decision.ID) { return(BadRequest()); } await _decisionService.ChangeDecisionAsync(decision); return(NoContent()); }
public async Task <IActionResult> Get(int id) { DecisionDTO decisionDto = await _decisionService.GetDecisionAsync(id); if (decisionDto == null) { return(NotFound()); } return(Ok(decisionDto)); }
public IHttpActionResult PostDecision(DecisionDTO decision) { if (ModelState.IsValid) { decision.Id = _decisionBLL.Insert(decision, _appicationContext.GetUserId()); return(Ok()); } else { return(BadRequest(ModelState)); } }
public async Task ChangeDecisionTest(string decisionNewName, string decisionNewDescription) { _decisionService = CreateDecisionService(); _repository.Setup(rep => rep.Decesion.GetFirstAsync(It.IsAny <Expression <Func <Decesion, bool> > >(), It.IsAny <Func <IQueryable <Decesion>, IIncludableQueryable <Decesion, object> > >())) .ReturnsAsync(GetTestDecesionQueryable().FirstOrDefault()); var changingDecisionDto = new DecisionDTO(); changingDecisionDto.Name = decisionNewName; changingDecisionDto.Description = decisionNewDescription; await _decisionService.ChangeDecisionAsync(changingDecisionDto); _repository.Verify(rep => rep.Decesion.GetFirstAsync(It.IsAny <Expression <Func <Decesion, bool> > >(), It.IsAny <Func <IQueryable <Decesion>, IIncludableQueryable <Decesion, object> > >()), Times.Once); }
public async Task Update_ReturnsOkObjectResult() { //Arrange var mockDecision = new DecisionDTO(); _decisionService .Setup(x => x.ChangeDecisionAsync(mockDecision)); //Act var result = await _decisionsController.Update(It.IsAny <int>(), mockDecision); //Assert _decisionService.Verify(); Assert.IsInstanceOf <NoContentResult>(result); }
public async Task Update_InvalidID() { //Arrange var expected = 1; var mockDecision = new DecisionDTO(); mockDecision.ID = 2; _decisionService .Setup(x => x.ChangeDecisionAsync(mockDecision)); //Act var result = await _decisionsController.Update(expected, mockDecision); //Assert _decisionService.Verify(); Assert.IsInstanceOf <BadRequestResult>(result); }
public IHttpActionResult PutDecision(DecisionDTO decision) { try { if (ModelState.IsValid) { decision.Id = _decisionBLL.Update(decision, _appicationContext.GetUserId()); return(Ok(decision)); } else { return(BadRequest(ModelState)); } } catch (Exception) { throw; } }
public ActionResult <Decision> PostDecision(DecisionDTO decision) { return(Ok(_repository.Create(decision))); }
public int Save(DecisionDTO obj, string currentuserId) { Decision decision; try { _unitOfWork.BeginTransaction(); if (obj.Id == 0) { decision = new Decision(); Mapper.Map <DecisionDTO, Decision>(obj, decision); if (obj.SelectedSectors.Count > 0) { foreach (int sector in obj.SelectedSectors) { decision.ActivitySectors.Add(_activitySectorRepository.Find(sector)); } } if (obj.SelectedCompaniesIds.Count > 0) { foreach (int company in obj.SelectedCompaniesIds) { decision.Companies.Add(_companyRepository.Find(company)); } } if (obj.SelectedDepartmentIds.Count > 0) { foreach (int department in obj.SelectedDepartmentIds) { decision.Departments.Add(_departmentRepository.Find(department)); decision.DecisionExecutions.Add(new DecisionExecution() { CreateDate = DateTime.Now, CreatedBy = currentuserId, Department = _departmentRepository.Find(department), DecisionStatus = 0, TrackingState = TrackableEntities.TrackingState.Added }); } } decision.CreateDate = DateTime.Now; decision.CreatedBy = currentuserId; base.Insert(decision); } else { decision = _repository .Query() .Include(c => c.ActivitySectors) .Include(c => c.Companies) .Include(c => c.Departments) .Include(c => c.DecisionExecutions) .SelectQueryable().Where(c => c.Id == obj.Id).FirstOrDefault(); Mapper.Map <DecisionDTO, Decision>(obj, decision); foreach (var s in decision.ActivitySectors) { decision.ActivitySectors.Remove(s); } foreach (var s in decision.Companies) { decision.Companies.Remove(s); } foreach (var s in decision.Departments) { decision.Departments.Remove(s); } foreach (var s in decision.DecisionExecutions) { if (!obj.SelectedDepartmentIds.Contains(s.DepartmentId)) { s.TrackingState = TrackableEntities.TrackingState.Deleted; } } _unitOfWork.SaveChanges(); if (obj.SelectedSectors.Count > 0) { foreach (int sector in obj.SelectedSectors) { decision.ActivitySectors.Add(_activitySectorRepository.Find(sector)); } } if (obj.SelectedCompaniesIds.Count > 0) { foreach (int company in obj.SelectedCompaniesIds) { decision.Companies.Add(_companyRepository.Find(company)); } } if (obj.SelectedDepartmentIds.Count > 0) { foreach (int department in obj.SelectedDepartmentIds) { decision.Departments.Add(_departmentRepository.Find(department)); } } if (obj.SelectedDepartmentIds.Count > 0) { foreach (int department in obj.SelectedDepartmentIds) { if (!decision.DecisionExecutions.Select(c => c.DepartmentId).Contains(department)) { decision.DecisionExecutions.Add(new DecisionExecution() { CreateDate = DateTime.Now, CreatedBy = currentuserId, Department = _departmentRepository.Find(department), DecisionStatus = 0, TrackingState = TrackableEntities.TrackingState.Added }); } } } decision.LastUpdateDate = DateTime.Now; decision.LastUpdateBy = currentuserId; base.Update(decision); } _unitOfWork.SaveChanges(); _unitOfWork.Commit(); return(decision.Id); } catch (Exception) { throw; } }
public int Update(DecisionDTO objDTO, string currentuserId) { var decId = objDTO.Id; objDTO.DecisionExecutions.ToList().ForEach(c => c.DepartmentName = _departmentService.Find(c.DepartmentId).Name); Decision decision = new Decision(); try { var isValid = !(_repository.Query().SelectQueryable().Where(c => c.DecisionNumber == objDTO.DecisionNumber && c.ConferenceYear != 0 && c.ConferenceYear == objDTO.ConferenceYear && c.Id != objDTO.Id).Any()); if (isValid) { _unitOfWork.BeginTransaction(); decision = _repository .Query() .SelectQueryable().Where(c => c.Id == objDTO.Id).FirstOrDefault(); var referenceItems = _referenceItemRepository.Query().SelectQueryable().Where(c => c.DecisionId == decision.Id).Select(c => c.Id).ToList(); foreach (var referenceItem in referenceItems) { if (!objDTO.ReferenceItems.Select(c => c.Id).ToList().Contains(referenceItem)) { _referenceItemRepository.Delete(referenceItem); } } _unitOfWork.SaveChanges(); var decisionExecutions = _decisionExecutionRepository.Query().SelectQueryable().Where(c => c.DecisionId == decision.Id).Select(c => c.Id).ToList(); foreach (var decisionExecution in decisionExecutions) { if (!objDTO.DecisionExecutions.Select(c => c.Id).ToList().Contains(decisionExecution)) { _decisionExecutionRepository.Delete(decisionExecution); } } _unitOfWork.SaveChanges(); Mapper.Map <DecisionDTO, Decision>(objDTO, decision); decision.TrackingState = TrackableEntities.TrackingState.Modified; foreach (var referenceItem in decision.ReferenceItems) { if (referenceItem.Id == 0) { referenceItem.TrackingState = TrackableEntities.TrackingState.Added; } else { referenceItem.TrackingState = TrackableEntities.TrackingState.Modified; } } foreach (var decisionExecution in decision.DecisionExecutions) { if (decisionExecution.Id == 0) { decisionExecution.TrackingState = TrackableEntities.TrackingState.Added; } else { decisionExecution.TrackingState = TrackableEntities.TrackingState.Modified; } } base.InsertOrUpdateGraph(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); Directory.Delete(Path.GetDirectoryName(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 (execution.Id == 0) { 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; } }