public HttpResponseMessage Post(Planes_Alimenticios varPlanes_Alimenticios)
        {
            if (ModelState.IsValid)
            {
                var data = "-1";
                try
                {
                    data = Convert.ToString(this.service.Insert(varPlanes_Alimenticios));
                    var bitacora = BitacoraHelper.GetBitacora(Request, object_id, Convert.ToInt32(data), BitacoraHelper.TypeSql.INSERT, "sp_InsPlanes_Alimenticios", new JavaScriptSerializer().Serialize(varPlanes_Alimenticios), true);
                    serviceBitacora.Insert(bitacora);
                }
                catch (ServiceException ex)
                {
                    var bitacora = BitacoraHelper.GetBitacora(Request, object_id, 0, BitacoraHelper.TypeSql.INSERT, "sp_InsPlanes_Alimenticios", new JavaScriptSerializer().Serialize(varPlanes_Alimenticios), true);
                    serviceBitacora.Insert(bitacora);
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, data, Configuration.Formatters.JsonFormatter));
            }
            else
            {
                var errors   = ModelState.SelectMany(m => m.Value.Errors.Select(err => err.ErrorMessage != string.Empty ? err.ErrorMessage : err.Exception.Message).ToList()).ToList();
                var bitacora = BitacoraHelper.GetBitacora(Request, object_id, 0, BitacoraHelper.TypeSql.INSERT, "sp_InsPlanes_Alimenticios", new JavaScriptSerializer().Serialize(varPlanes_Alimenticios), false, errors.ToString());
                serviceBitacora.Insert(bitacora);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
            }
        }
        public HttpResponseMessage Delete(int id)
        {
            Planes_Alimenticios varPlanes_Alimenticios = this.service.GetByKey(id, false);
            bool result = false;

            if (varPlanes_Alimenticios == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            try
            {
                result = this.service.Delete(id);//, globalData, dataReference);
                var bitacora = BitacoraHelper.GetBitacora(Request, object_id, id, BitacoraHelper.TypeSql.DELETE, "sp_DelPlanes_Alimenticios", new JavaScriptSerializer().Serialize(varPlanes_Alimenticios), result);
                serviceBitacora.Insert(bitacora);
            }
            catch (ServiceException ex)
            {
                var bitacora = BitacoraHelper.GetBitacora(Request, object_id, id, BitacoraHelper.TypeSql.DELETE, "sp_DelPlanes_Alimenticios", new JavaScriptSerializer().Serialize(varPlanes_Alimenticios), result, ex.Message);
                serviceBitacora.Insert(bitacora);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
        public HttpResponseMessage PutTunnel(Planes_Alimenticios emp, string user, string password)
        {
            var client = new System.Net.WebClient();

            client.Headers = TokenManager.GetAuthenticationHeader(user, password);
            client.Headers["Content-Type"] = "application/json";
            var dataString = new JavaScriptSerializer().Serialize(emp);

            var result = client.UploadString(new Uri(baseApi + ApiControllerUrl + "/Put?Id=" + emp.Folio), "PUT"
                                             , dataString);

            return(Request.CreateResponse(HttpStatusCode.OK, result, Configuration.Formatters.JsonFormatter));
        }
        public HttpResponseMessage Put_Datos_Generales(Planes_Alimenticios varPlanes_Alimenticios_Datos_Generales)
        {
            var data = "-1";

            try
            {
                data = Convert.ToString(this.service.Update_Datos_Generales(varPlanes_Alimenticios_Datos_Generales));
                var bitacora = BitacoraHelper.GetBitacora(Request, object_id, varPlanes_Alimenticios_Datos_Generales.Folio, BitacoraHelper.TypeSql.UPDATE, "sp_UpdPlanes_Alimenticios", new JavaScriptSerializer().Serialize(varPlanes_Alimenticios_Datos_Generales), true);
                serviceBitacora.Insert(bitacora);
            }
            catch (ServiceException ex)
            {
                var bitacora = BitacoraHelper.GetBitacora(Request, object_id, varPlanes_Alimenticios_Datos_Generales.Folio, BitacoraHelper.TypeSql.UPDATE, "sp_UpdPlanes_Alimenticios", new JavaScriptSerializer().Serialize(varPlanes_Alimenticios_Datos_Generales), false, ex.Message);
                serviceBitacora.Insert(bitacora);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, data, Configuration.Formatters.JsonFormatter));
        }
        public HttpResponseMessage Planes_AlimenticiosGenerateID()
        {
            Planes_Alimenticios varPlanes_Alimenticios = new Planes_Alimenticios();
            var data = "-1";

            try
            {
                data = Convert.ToString(this.service.Insert(varPlanes_Alimenticios));
                var bitacora = BitacoraHelper.GetBitacora(Request, object_id, Convert.ToInt32(data), BitacoraHelper.TypeSql.INSERT, "sp_Planes_AlimenticiosGenerateID", new JavaScriptSerializer().Serialize(varPlanes_Alimenticios), true);
                serviceBitacora.Insert(bitacora);
            }
            catch (ServiceException ex)
            {
                var bitacora = BitacoraHelper.GetBitacora(Request, object_id, 0, BitacoraHelper.TypeSql.INSERT, "sp_Planes_AlimenticiosGenerateID", new JavaScriptSerializer().Serialize(varPlanes_Alimenticios), true);
                serviceBitacora.Insert(bitacora);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, data, Configuration.Formatters.JsonFormatter));
        }
        public HttpResponseMessage Get_Datos_Generales(int id)
        {
            Planes_Alimenticios entity = this.service.ListaSelAll(1, 1, "Planes_Alimenticios.Folio='" + id.ToString() + "'", "").Planes_Alimenticioss.First();
            Planes_Alimenticios result = new Planes_Alimenticios();

            result.Folio                = entity.Folio;
            result.Fecha_de_Registro    = entity.Fecha_de_Registro;
            result.Hora_de_Registro     = entity.Hora_de_Registro;
            result.Usuario_que_Registra = entity.Usuario_que_Registra;
            result.Usuario_que_Registra_Spartan_User = entity.Usuario_que_Registra_Spartan_User;
            result.Fecha_inicio_del_Plan             = entity.Fecha_inicio_del_Plan;
            result.Fecha_fin_del_Plan = entity.Fecha_fin_del_Plan;
            result.Semana             = entity.Semana;
            result.Paciente           = entity.Paciente;
            result.Paciente_Pacientes = entity.Paciente_Pacientes;
            result.Estatus            = entity.Estatus;
            result.Estatus_Estatus    = entity.Estatus_Estatus;

            return(Request.CreateResponse(HttpStatusCode.OK, result, Configuration.Formatters.JsonFormatter));
        }