public async Task <IBaseDTO> Update(IBaseDTO newDto) { EmployeeDTO newEmp = (EmployeeDTO)newDto; EmployeeDTO oldEmp = (EmployeeDTO)await _employeeRep.GetById(newDto.Id); if (oldEmp.DepartmentId != newEmp.DepartmentId) { if (newEmp.Probation) { newDto.SetError("Нельзя переводить сотрудника на исп. сроке!"); return(newEmp); } var department = (CatalogDepartmentDTO)await _departmentRep.GetById(newEmp.DepartmentId); if (department.IsFull() && newEmp.TransferHeadAssent == false) { newDto.SetError("Нельзя переводить сотрудника в отдел с максимальным кол-ом сотрудников, без согласия руководства!"); return(newEmp); } EmployeeTransferDTO transfer = new EmployeeTransferDTO() { Confirm = true, ConfirmDate = DateTime.Now, EmployeeId = newEmp.Id, ToDepartmentId = newEmp.DepartmentId }; await _transferRep.Add(transfer); } return(await _employeeRep.Update(newDto)); }
/// <summary> /// Fonction de validation de Type /// </summary> /// <typeparam name="T">Type attendu</typeparam> /// <param name="pObject">Objet a test</param> /// <remarks>LOUIS Yoann 12/02/2016</remarks> public static void ValidateType <T>(IBaseDTO pObject) { if ((pObject is T) == false) { throw new DTOLibrary.Exception.GeneriqueException.TypeException <T>(); } }
public async Task <IBaseDTO> Add(IBaseDTO dto) { EmployeeDTO newEmp = (EmployeeDTO)dto; if (newEmp.QualificationId > (int)QualificationNames.Инженер) { newEmp.SetError("Новый сотрудник не должен быть выше по квалификации, чем 'Инженер'."); return(newEmp); } if (newEmp.Probation == false) { newEmp.SetError("Новый сотрудник должен быть на испытательном сроке."); return(newEmp); } if (new int[] { 1, 2, 3 }.Contains(newEmp.ProbationDays) == false) { newEmp.SetError("У нового сотрудника должен быть задан исп. срок (1, 2 или 3 месяца)!"); return(newEmp); } EmployeeTransferDTO transfer = new EmployeeTransferDTO() { Confirm = true, ConfirmDate = DateTime.Now, EmployeeId = newEmp.Id, ToDepartmentId = newEmp.DepartmentId }; await _transferRep.Add(transfer); return(await _employeeRep.Add(dto)); }
public async Task <IHttpActionResult> Get(int id) { IBaseDTO dto = await Service.GetById(id); if (dto == null) { return(StatusCode(HttpStatusCode.NotAcceptable)); } return(Ok(dto)); }
public async Task <IHttpActionResult> Get(string name, int id) { IBaseDTO dto = await _service.GetById(name, id); if (dto == null) { return(NotFound()); } return(Ok(dto)); }
/// <summary> /// Permet de retourner un seul item /// </summary> /// <typeparam name="TDTO">Type de dto</typeparam> /// <typeparam name="TMETIER">type du metier</typeparam> /// <param name="pCritere">cvritere de recherche</param> /// <returns>TDTO</returns> /// <remarks>LOUIS YOANN 06/09/2016</remarks> public static TDTO GetItem <TDTO, TMETIER>(IBaseDTO pCritere) where TDTO : IBaseDTO where TMETIER : IBaseMetier, new() { // yl - Initalisation Metier var lMetier = new TMETIER(); // yl - Convertir la liste return((TDTO)lMetier.GetItem(new DTOLibrary.Info.InfoSessionDTO(), pCritere)); }
/// <summary> /// Retoune une liste d'items /// </summary> /// <typeparam name="TDTO">Type de dto</typeparam> /// <typeparam name="TMETIER">Type du metier</typeparam> /// <param name="pCritere">Critere de recherche</param> /// <returns>ObservableCollection de TDTO</returns> /// <remarks>LOUIS YOANN 06/09/2016</remarks> public static ObservableCollection <TDTO> GetItems <TDTO, TMETIER>(IBaseDTO pCritere) where TDTO : IBaseDTO where TMETIER : IBaseMetier, new() { // yl - Initalisation Metier var lMetier = new TMETIER(); var lListTmp = lMetier.GetItems(new DTOLibrary.Info.InfoSessionDTO(), pCritere).ToList(); // yl - Convertir la liste return(Helper.TypeHelper.ListIToObservableObject <TDTO>(lListTmp)); }
public void Update(IBaseDTO dto) { TDto item = _values.SingleOrDefault(v => v.Id == dto.Id); if (item == null) { return; } int index = _values.IndexOf(item); _values[index] = (TDto)dto; }
public async Task <IBaseDTO> Update(IBaseDTO dto) { try { TEntity entity = Mapper.Map <TEntity>(dto); TEntity newEntity = await Db.UpdateAsync(entity); return(Mapper.Map <TDto>(newEntity)); } catch (Exception ex) { throw; } }
public async Task <IHttpActionResult> Update(string name, [FromBody] IBaseDTO item) { if (item == null) { return(BadRequest()); } IBaseDTO dto = await _service.Update(name, item); if (dto == null) { return(NotFound()); } return(Ok(dto)); }
public async Task <IHttpActionResult> Update([FromBody] IBaseDTO item) { if (item == null) { return(BadRequest()); } IBaseDTO dto = await Service.Update(item); if (dto == null) { return(StatusCode(HttpStatusCode.NotAcceptable)); } return(Ok(dto)); }
public void GetAll() { Task <IEnumerable <IBaseDTO> > t = _service.GetAll(); t.Wait(); var list = t.Result as IEnumerable <IBaseDTO>; Assert.IsNotNull(list); int c = list.Count(); Assert.AreNotEqual(0, c); IBaseDTO firstDto = list.First(); EmployeeDTO dto = firstDto as EmployeeDTO; }
/// <summary> /// Creation d'un string xml a partir d'un dto. /// </summary> /// <param name="dto">DTO</param> /// <returns>XML</returns> /// <remarks>LOUIS Yoann 16/06/2015 Version 1.0.1</remarks> public static string SerializeDTO(IBaseDTO dto) { try { XmlSerializer xmlSer = new XmlSerializer(dto.GetType()); StringWriter sWriter = new StringWriter(); // yl - Serializsation dto vers xml. xmlSer.Serialize(sWriter, dto); // yl - Retourne string of xml. on remplace les < par ¤ pour autoriser le tranfere return(sWriter.ToString()); } catch (System.Exception ex) { throw ex; } }
public async Task <IBaseDTO> Add(IBaseDTO dto) { try { TEntity entity = Mapper.Map <TEntity>(dto); entity = await Db.AddAsync(entity); return(Mapper.Map <TDto>(entity)); } catch (Exception ex) { return(await Task.FromResult <IBaseDTO>(null)); //return null; } }
/// <summary> /// Supprimer des elment /// </summary> /// <param name="pCritere">Critere des element a suppruimer</param> /// <remarks>LOUIS YOANN 24/06/2015</remarks> public virtual void RemoveItems(InfoSessionDTO pInfoSession, IBaseDTO pCritere) { try { // yl - Log WriteDebugLogger(pInfoSession); DALType lService = new DALType(); // yl - remove lService.RemoveItems(pCritere as CritereDTOType); } catch (Exception lEx) { WriteErrorLogger(pInfoSession, lEx); throw (ExceptionType)Activator.CreateInstance(typeof(ExceptionType), lEx); } }
/// <summary> /// Méthode qui permet le chargement d'une liste d'utilisateur /// </summary> /// <param name="pAuth">User en cours</param> /// <returns>Une liste d'utilisateur au format AuthentificationDTO</returns> /// <remarks>JClaud 2015-11-12 Création</remarks> public ObservableCollection <IBaseDTO> GetListeData(IBaseDTO pAuth) { //jc- déclaration de variables ObservableCollection <AuthentificationDTO> lListeFinale = new ObservableCollection <AuthentificationDTO>(); AuthentificationDTO lUser = ((CritereAuthentificationDTO)pAuth).AuthentificationDTO; //jc- on récupère la liste des utilisateurs au format AuthentificationDTO List <UserDto> lListTemp = LanceAuthentification(CopyUserAsAPI(lUser)).User.GetActive(); //jc- TODO - A VOIR POURQUOI IMPOSSIBLE DE CHARGER PLUS DE 220 ROWS //.Where(s => s.Entity.Active == true).Take(50) //.ToList(); lListTemp.ToList().ForEach(p => lListeFinale.Add(ConvertUserDtoToAuth(p))); //jc- retourne la liste d'users return(new ObservableCollection <IBaseDTO>(lListeFinale)); }
/// <summary> /// Fonction permettant de retourner l'objet /// correspondant au critère de sélection /// </summary> /// <param name="pCritere">Critère de sélection</param> /// <returns>Objet DTO</returns> /// <remarks>Guillaume Bécard - 2015-06-24 - Création</remarks> public virtual IBaseDTO GetItem(InfoSessionDTO pInfoSession, IBaseDTO pCritere) { try { // yl - Log WriteDebugLogger(pInfoSession); // yl - Validation Critere this.ValidatedCritere(pCritere); //gb - Déclaration du service DALType lService = new DALType(); //gb - Appel de la fonction de récupération de l'item return(lService.GetItem(pCritere as CritereDTOType)); } catch (Exception lEx) { WriteErrorLogger(pInfoSession, lEx); throw (ExceptionType)Activator.CreateInstance(typeof(ExceptionType), lEx); } }
private FinancialController MockController(IBaseDTO payResult = null, IBaseDTO receiveResult = null, List <Balance> balancesResult = null) { if (payResult == null) { payResult = new OkDTO("x"); } if (receiveResult == null) { receiveResult = new OkDTO("y"); } if (balancesResult == null) { balancesResult = new List <Balance>(); } // Mock var mockPaymentService = new Mock <IPaymentService>(); mockPaymentService.Setup(service => service.EnqueueToPay(It.IsAny <Entry>())).Returns(Task.FromResult <IBaseDTO>(payResult)); // Mock var mockReceiptService = new Mock <IReceiptService>(); mockReceiptService.Setup(service => service.EnqueueToReceive(It.IsAny <Entry>())).Returns(Task.FromResult <IBaseDTO>(receiveResult)); var mockBalanceService = new Mock <IBalanceService>(); mockBalanceService.Setup(service => service.CashFlow(It.IsAny <Account>())).Returns(balancesResult); return(new FinancialController(mockPaymentService.Object, mockReceiptService.Object, mockBalanceService.Object)); }
/// <summary> /// Update un DTO /// </summary> /// <param name="pEntity">DTO a lmettre a jour</param> /// <remarks>LOUIS YOANN 24/06/2015</remarks> public virtual void UpdateItem(InfoSessionDTO pInfoSession, IBaseDTO pEntity) { try { // yl - Log WriteDebugLogger(pInfoSession); // yl - Validation Entity this.ValidatedDTO(pEntity); // yl - msie en place du service DALType lService = new DALType(); // yl - Cast var lEntity = (DTOType)pEntity; // yl - Update lService.UpdateItem(lEntity); } catch (Exception lEx) { WriteErrorLogger(pInfoSession, lEx); throw (ExceptionType)Activator.CreateInstance(typeof(ExceptionType), lEx); } }
/// <summary> /// Fonction permettant de retourner la liste des items /// en fonction du critère de sélection /// </summary> /// <param name="pCritere">Critère de sélection</param> /// <returns>Liste d'objet DTO</returns> /// <remarks>Guillaume Bécard - 2015-06-24 - Création</remarks> public virtual IEnumerable <IBaseDTO> GetItems(InfoSessionDTO pInfoSession, IBaseDTO pCritere) { try { // yl - Log WriteDebugLogger(pInfoSession); // yl - Validation Critere this.ValidatedCritere(pCritere); //gb - Déclaration du service DALType lService = new DALType(); //gb - Appel de la fonction de récupération des items return(lService.GetItems(pCritere as CritereDTOType).List.Cast <IBaseDTO>()); } catch (Exception lEx) { // yl - ecriture d'un log d'erreur WriteErrorLogger(pInfoSession, lEx); // yl - on leve une exception de type ExceptionType avec en iner exception l'exception catcher throw (ExceptionType)Activator.CreateInstance(typeof(ExceptionType), lEx); } }
public async Task <IBaseDTO> Add(IBaseDTO dto) { return(await _transferLogRep.Add(dto)); }
public async Task <IBaseDTO> Update(IBaseDTO dto) { return(await _changeLogRep.Update(dto)); }
public void Add(IBaseDTO dto) { _values.Add((TDto)dto); }
/// <summary> /// Valide le Critere de recherche /// </summary> /// <param name="pCritere">Critere de recherche du DTO</param> /// <remarks>LOUIS Yoann 11/02/2016</remarks> public virtual void ValidatedCritere(IBaseDTO pCritere) { // yl - test que le type de l'object et bien du type CritereDTOType ValidateType <CritereDTOType>(pCritere); }
public async Task <IBaseDTO> Update(IBaseDTO dto) { return(await _transferLogRep.Update(dto)); }
public async Task <IBaseDTO> Add(IBaseDTO dto) { return(await _changeLogRep.Add(dto)); }
/// <summary> /// Valide le DTO /// </summary> /// <param name="pEntity">Entité a valider</param> /// <remarks>LOUIS Yoann 11/02/2016</remarks> public virtual void ValidatedDTO(IBaseDTO pEntity) { // yl - test que le type de l'object et bien du type DTOType ValidateType <DTOType>(pEntity); }