public HttpResponseMessage Post(Detalle_Contratos_Empresa varDetalle_Contratos_Empresa)
        {
            if (ModelState.IsValid)
            {
                var data = "-1";
                try
                {
                    data = Convert.ToString(this.service.Insert(varDetalle_Contratos_Empresa));
                    var bitacora = BitacoraHelper.GetBitacora(Request, object_id, Convert.ToInt32(data), BitacoraHelper.TypeSql.INSERT, "sp_InsDetalle_Contratos_Empresa", new JavaScriptSerializer().Serialize(varDetalle_Contratos_Empresa), true);
                    serviceBitacora.Insert(bitacora);
                }
                catch (ServiceException ex)
                {
                    var bitacora = BitacoraHelper.GetBitacora(Request, object_id, 0, BitacoraHelper.TypeSql.INSERT, "sp_InsDetalle_Contratos_Empresa", new JavaScriptSerializer().Serialize(varDetalle_Contratos_Empresa), 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_InsDetalle_Contratos_Empresa", new JavaScriptSerializer().Serialize(varDetalle_Contratos_Empresa), false, errors.ToString());
                serviceBitacora.Insert(bitacora);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
            }
        }
        public HttpResponseMessage Delete(int id)
        {
            Detalle_Contratos_Empresa varDetalle_Contratos_Empresa = this.service.GetByKey(id, false);
            bool result = false;

            if (varDetalle_Contratos_Empresa == 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_DelDetalle_Contratos_Empresa", new JavaScriptSerializer().Serialize(varDetalle_Contratos_Empresa), result);
                serviceBitacora.Insert(bitacora);
            }
            catch (ServiceException ex)
            {
                var bitacora = BitacoraHelper.GetBitacora(Request, object_id, id, BitacoraHelper.TypeSql.DELETE, "sp_DelDetalle_Contratos_Empresa", new JavaScriptSerializer().Serialize(varDetalle_Contratos_Empresa), result, ex.Message);
                serviceBitacora.Insert(bitacora);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
        public ActionResult Post(bool IsNew, Detalle_Contratos_EmpresaModel varDetalle_Contratos_Empresa)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!_tokenManager.GenerateToken())
                    {
                        return(Json(null, JsonRequestBehavior.AllowGet));
                    }
                    _IDetalle_Contratos_EmpresaApiConsumer.SetAuthHeader(_tokenManager.Token);


                    if (varDetalle_Contratos_Empresa.DocumentoRemoveAttachment != 0 && varDetalle_Contratos_Empresa.DocumentoFile == null)
                    {
                        varDetalle_Contratos_Empresa.Documento = 0;
                    }

                    if (varDetalle_Contratos_Empresa.DocumentoFile != null)
                    {
                        var fileAsBytes = HttpPostedFileHelper.GetPostedFileAsBytes(varDetalle_Contratos_Empresa.DocumentoFile);
                        _ISpartane_FileApiConsumer.SetAuthHeader(_tokenManager.Token);
                        varDetalle_Contratos_Empresa.Documento = (int)_ISpartane_FileApiConsumer.Insert(new Spartane_File()
                        {
                            File        = fileAsBytes,
                            Description = varDetalle_Contratos_Empresa.DocumentoFile.FileName,
                            File_Size   = fileAsBytes.Length
                        }).Resource;
                    }


                    var result = "";
                    var Detalle_Contratos_EmpresaInfo = new Detalle_Contratos_Empresa
                    {
                        Folio              = varDetalle_Contratos_Empresa.Folio
                        , Suscripcion      = varDetalle_Contratos_Empresa.Suscripcion
                        , Tipo_de_Contrato = varDetalle_Contratos_Empresa.Tipo_de_Contrato
                        , Documento        = (varDetalle_Contratos_Empresa.Documento.HasValue && varDetalle_Contratos_Empresa.Documento != 0) ? ((int?)Convert.ToInt32(varDetalle_Contratos_Empresa.Documento.Value)) : null

                        , Fecha_de_Firma_de_Contrato = (!String.IsNullOrEmpty(varDetalle_Contratos_Empresa.Fecha_de_Firma_de_Contrato)) ? DateTime.ParseExact(varDetalle_Contratos_Empresa.Fecha_de_Firma_de_Contrato, ConfigurationProperty.DateFormat, CultureInfo.InvariantCulture as IFormatProvider) : (DateTime?)null
                    };

                    result = !IsNew?
                             _IDetalle_Contratos_EmpresaApiConsumer.Update(Detalle_Contratos_EmpresaInfo, null, null).Resource.ToString() :
                                 _IDetalle_Contratos_EmpresaApiConsumer.Insert(Detalle_Contratos_EmpresaInfo, null, null).Resource.ToString();

                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
            catch (ServiceException ex)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }
        public HttpResponseMessage PutTunnel(Detalle_Contratos_Empresa 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 Get_Datos_Generales(int id)
        {
            Detalle_Contratos_Empresa entity = this.service.ListaSelAll(1, 1, "Detalle_Contratos_Empresa.Folio='" + id.ToString() + "'", "").Detalle_Contratos_Empresas.First();
            Detalle_Contratos_Empresa result = new Detalle_Contratos_Empresa();

            result.Folio       = entity.Folio;
            result.Suscripcion = entity.Suscripcion;
            result.Suscripcion_Planes_de_Suscripcion = entity.Suscripcion_Planes_de_Suscripcion;
            result.Tipo_de_Contrato = entity.Tipo_de_Contrato;
            result.Tipo_de_Contrato_Tipos_de_Contrato = entity.Tipo_de_Contrato_Tipos_de_Contrato;
            result.Documento = entity.Documento;
            result.Documento_Spartane_File    = entity.Documento_Spartane_File;
            result.Fecha_de_Firma_de_Contrato = entity.Fecha_de_Firma_de_Contrato;

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

            try
            {
                data = Convert.ToString(this.service.Update_Datos_Generales(varDetalle_Contratos_Empresa_Datos_Generales));
                var bitacora = BitacoraHelper.GetBitacora(Request, object_id, varDetalle_Contratos_Empresa_Datos_Generales.Folio, BitacoraHelper.TypeSql.UPDATE, "sp_UpdDetalle_Contratos_Empresa", new JavaScriptSerializer().Serialize(varDetalle_Contratos_Empresa_Datos_Generales), true);
                serviceBitacora.Insert(bitacora);
            }
            catch (ServiceException ex)
            {
                var bitacora = BitacoraHelper.GetBitacora(Request, object_id, varDetalle_Contratos_Empresa_Datos_Generales.Folio, BitacoraHelper.TypeSql.UPDATE, "sp_UpdDetalle_Contratos_Empresa", new JavaScriptSerializer().Serialize(varDetalle_Contratos_Empresa_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 Detalle_Contratos_EmpresaGenerateID()
        {
            Detalle_Contratos_Empresa varDetalle_Contratos_Empresa = new Detalle_Contratos_Empresa();
            var data = "-1";

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

            return(Request.CreateResponse(HttpStatusCode.OK, data, Configuration.Formatters.JsonFormatter));
        }
        public ActionResult Delete(int id)
        {
            try
            {
                if (!_tokenManager.GenerateToken())
                {
                    return(Json(null, JsonRequestBehavior.AllowGet));
                }
                _IDetalle_Contratos_EmpresaApiConsumer.SetAuthHeader(_tokenManager.Token);

                Detalle_Contratos_Empresa varDetalle_Contratos_Empresa = null;
                if (id.ToString() != "0")
                {
                    string where = "";
                }
                var result = _IDetalle_Contratos_EmpresaApiConsumer.Delete(id, null, null).Resource;
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (ServiceException ex)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }