/// <summary> /// Allow set any meta-key for user (attributes) /// </summary> /// <returns></returns> public ActionResponse FillDataUserAction(FillUserDataRequest obj) { ActionResponse output = new ActionResponse(); try { // STEP 0.1: Verify if user exists ClienteData clientData = new ClienteData(); Cliente oClient = clientData.GetUserById(obj.idClient.Value); if (oClient.id_cliente == null) { return(functions.Response((int)CodeStatusEnum.NO_CONTENT, "No existe el usuario en el sistema", null)); } ParamData paramData = new ParamData(); ClienteParamData clientParamData = new ClienteParamData(); // Detect if meta-key already exists or not // tags length is equal to values length int l = obj.tags.Length; // Try to check and store params objects List <Param> paramList = new List <Param>(); decimal id_cliente = obj.idClient.Value; for (int i = 0; i < l; i++) { string tag = obj.tags[i]; // Check if param already exists or not Param param = paramData.GetByTag(tag); if (param.idParam != null) { // Check if meta-key exists ClienteParam cp = clientParamData.GetByIdClienteAndIdParam(id_cliente, param.idParam.Value); if (cp.idClienteParam != null) { return(functions.Response((int)CodeStatusEnum.CONFLICT, "Ya existe un valor asociado para el usuario y tag [" + param.tag + "]", null)); } paramList.Add(param); } else { return(functions.Response((int)CodeStatusEnum.NO_CONTENT, "No existe el tag [" + tag + "]", null)); } } // Start to insert new meta-data int j = 0; foreach (Param o in paramList) { string value = obj.values[j]; int idParam = o.idParam.Value; int res = clientParamData.FillData(id_cliente, idParam, value); if (res <= 0) { return(functions.Response((int)CodeStatusEnum.INTERNAL_ERROR, "Falló la creación de la meta-data para el tag [" + o.tag + "]", null)); } } FillDataUserResponse response = new FillDataUserResponse(); response.numberOfItemsInserted = l; return(functions.Response((int)CodeStatusEnum.OK, "OK", response)); } catch (Exception e) { return(functions.Response((int)CodeStatusEnum.INTERNAL_ERROR, "Error desconocido en el sistema", null)); } }
public IHttpActionResult FillUserData([FromBody] FillUserDataRequest obj) { try { ClienteParamController clienteParamController = new ClienteParamController(); // Verify at least object arrives with data if (obj == null) { throw new NotEnoughAttributesException("No se ha recibido ningún parámetro"); } // Verify for parameters needed if (obj.idClient == null || obj.tags == null || obj.values == null) { throw new NotEnoughAttributesException("No se han recibido todos los parámetros requeridos"); } // Check params's integrity if (obj.idClient.GetType() != typeof(decimal) || obj.tags.GetType() != typeof(string[]) || obj.values.GetType() != typeof(string[])) { throw new NotValidDataException("Los tipos de datos no coinciden"); } // Check if number of tags and values is correct int n = obj.tags.Length; int m = obj.values.Length; if (n != m) { throw new NotValidDataException("Los valores proporcionados no coinciden con el número de tags enviados"); } // Call core ActionResponse action = clienteParamController.FillDataUserAction(obj); if (action.code == (int)CodeStatusEnum.OK) { return(ResponseOk(action.data)); } // OK else { return(ResponseError(action.code, action.message)); } // NOK } catch (NotValidDataException e) { logger.Error(e.Message); return(ResponseError((int)CodeStatusEnum.BAD_REQUEST, e.Message)); } catch (NotEnoughAttributesException e) { logger.Error(e.Message); return(ResponseError((int)CodeStatusEnum.BAD_REQUEST, e.Message)); } catch (Exception ex) { logger.Fatal(ex.Message); return(ResponseError((int)CodeStatusEnum.INTERNAL_ERROR, "Error desconocido en el sistema")); } }