private PreRequest_Observation SetDataToObservation(int pPreRequest_id, string pObservation, string pUsu_document) { PreRequest_Observation Observation = new PreRequest_Observation(); Observation.preReq_id = pPreRequest_id; Observation.prObs_observation = pObservation; Observation.usu_document = pUsu_document; Observation.prObs_registrationDate = DateTime.Now; return(Observation); }
private bool InsertObservationInDB(PreRequest_Observation pPbservation) { try { using (BDRAEntities db = new BDRAEntities()) { db.PreRequest_Observation.Add(pPbservation); db.SaveChanges(); return(true); } } catch (Exception ex) { return(false); } }
public IHttpActionResult UpdatePreRequest(PreRequestViewModel pPreRequest) { try { ResponseViewModel rta = new ResponseViewModel(); using (BDRAEntities db = new BDRAEntities()) { //TODO: Update client var preRequestBD = db.PreRequest.Where(p => p.preReq_id == pPreRequest.id).FirstOrDefault(); preRequestBD.firstCanal_id = pPreRequest.firstCanal.id; preRequestBD.secondCanal_id = pPreRequest.secondCanal.id; preRequestBD.sta_id = pPreRequest.stateRequest.id; if (pPreRequest.vehicleModel.id != null && pPreRequest.vehicleModel.id != 0) { preRequestBD.vehMdl_id = pPreRequest.vehicleModel.id; } else { var vechicleModel = VehicleModelController.SetDataToVehicleModel(pPreRequest.vehicleModel); var vehicleModelDB = VehicleModelController.CreateVehicleModelInDB(vechicleModel); preRequestBD.vehMdl_id = vehicleModelDB.id; } preRequestBD.preCli_id = pPreRequest.preClient.idPreClient; db.SaveChanges(); if (pPreRequest.lsObservation[0].observation != "") { int idPreRequest = int.Parse(pPreRequest.id.ToString()); PreRequest_Observation observation = this.SetDataToObservation(idPreRequest, pPreRequest.lsObservation[0].observation, pPreRequest.user.id); this.InsertObservationInDB(observation); } rta.response = true; rta.message = "Se ha actualizado la solicitud: " + pPreRequest.id; return(Ok(rta)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult AddNewPreRequest(PreRequestViewModel pPreRequest) { try { this.objPreClientController = new PreClientController(); ResponseViewModel rta = new ResponseViewModel(); using (BDRAEntities db = new BDRAEntities()) { /* * Validamos si el PreCliente de la solicitud ya existe en la base de datos. */ PreClient PreClientBD = new PreClient(); PreClientBD = objPreClientController.GetPreClientBD(pPreRequest.preClient); if (PreClientBD == null) { PreClientBD = objPreClientController.SetDataToPreClient(pPreRequest.preClient, pPreRequest.user); var preClientCreated = objPreClientController.CreatePreClientInBD(PreClientBD); if (preClientCreated) { PreClientBD = objPreClientController.GetPreClientBD(pPreRequest.preClient); } } PreRequest oPreRequest = new PreRequest(); oPreRequest.preReq_registrationDate = DateTime.Now; oPreRequest.preCli_id = PreClientBD.preCli_id; oPreRequest.preReq_state = true; oPreRequest.usu_document = pPreRequest.user.id; if (pPreRequest.vehicleModel.id != null && pPreRequest.vehicleModel.id != 0) { oPreRequest.vehMdl_id = pPreRequest.vehicleModel.id; } else { var vechicleModel = VehicleModelController.SetDataToVehicleModel(pPreRequest.vehicleModel); var vehicleModelDB = VehicleModelController.CreateVehicleModelInDB(vechicleModel); oPreRequest.vehMdl_id = vehicleModelDB.id; } if (pPreRequest.stateRequest != null) { oPreRequest.sta_id = pPreRequest.stateRequest.id; } if (pPreRequest.firstCanal != null) { oPreRequest.firstCanal_id = pPreRequest.firstCanal.id; } if (pPreRequest.secondCanal != null) { oPreRequest.secondCanal_id = pPreRequest.secondCanal.id; } db.PreRequest.Add(oPreRequest); db.SaveChanges(); var lastRequest = GetTheLastPreRequestByPreClient(PreClientBD); if (pPreRequest.lsObservation[0].observation != "") { PreRequest_Observation observation = this.SetDataToObservation(lastRequest.preReq_id, pPreRequest.lsObservation[0].observation, pPreRequest.user.id); this.InsertObservationInDB(observation); } rta.response = true; rta.message = "Se ha creado la pre solicitud: " + lastRequest.preReq_id + " de cliente de persona natural"; return(Ok(rta)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }