/// <summary> /// Modify all data of client /// </summary> /// <param name="objClient"></param> /// <returns></returns> public DTResponse ModifyClient(DTClient objClient) { DTResponse Resp = new DTResponse(); try { Client Client = _ObjClientRepository.GetAllBy(i => i.IdClient == objClient.IdClient).FirstOrDefault(); //Calculate available credit if (Client != null) { int diferenceCredit = objClient.CreditLimit - Client.CreditLimit; objClient.AvailableCredit = objClient.AvailableCredit + diferenceCredit; } objClient.Nit = Base64Encode(objClient.Nit); //Client ClientBD = new Client(); Client = _Objmapper.Map <Client>(objClient); _ObjClientRepository.Update(Client); Resp.response = true; Resp.message = "Success"; } catch (Exception ex) { Resp.response = false; Resp.message = ex.Message; } return(Resp); }
/// <summary> /// Get all clients of data base /// </summary> /// <returns>List<DTClient></returns> public List <DTClient> GetAllClients() { List <DTClient> ListClient = new List <DTClient>(); try { var Query = _ObjClientRepository.GetAll(); if (Query != null) { foreach (Client item in Query) { DTClient objClient = new DTClient(); item.Nit = Base64Decode(item.Nit); objClient = _Objmapper.Map <DTClient>(item); ListClient.Add(objClient); } } return(ListClient); } catch (Exception ex) { throw ex; } }
/// <summary> /// Insert new clients /// </summary> /// <param name="objClient"></param> /// <returns>DTResponse</returns> public DTResponse CreateClient(DTClient objClient) { DTResponse Resp = new DTResponse(); try { objClient.Nit = Base64Encode(objClient.Nit); Client ClientBD = new Client(); ClientBD = _Objmapper.Map <Client>(objClient); _ObjClientRepository.Create(ClientBD); Resp.response = true; Resp.message = "Success"; } catch (Exception ex) { Resp.message = ex.Message; } return(Resp); }
public ActionResult <DTResponse> ModifyClient(DTClient objClient) { DTResponse Resp = new DTResponse(); DTClientValidator objClientValidator = new DTClientValidator(); ValidationResult result = new ValidationResult(); //Validate fields required result = objClientValidator.Validate(objClient); if (result.IsValid) { Resp = _ObjClient.ModifyClient(objClient); } else { Resp.response = false; foreach (var failure in result.Errors) { Resp.message += "Error was: " + failure.ErrorMessage + "-> "; } } return(Resp); }