Ejemplo n.º 1
0
        private void StoreApi(ref int id, string apiUrl, ref string username, string initialFileName, string fileName)
        {
            var record = new Models.ImportedFile {
                DateCreated = DateTime.UtcNow, Ip = Request.UserHostAddress, FileName = fileName
            };

            if (username == null)
            {
                username = Request.Cookies["guid"] != null?Server.UrlDecode(Request.Cookies["guid"].Value) : null;

                if (username == null)
                {
                    username = Guid.NewGuid().ToString() + "@anonymous" + DateTime.Now.Year + ".com";
                }
            }

            var newApi = new Models.Apis
            {
                ApiName    = initialFileName,
                ApiUrl     = apiUrl,
                Owner      = username,
                FileSource = record
            };

            dbContext.Entry(newApi).State = System.Data.Entity.EntityState.Added;
            dbContext.SaveChanges();
            id = newApi.Id;
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Delete(int apiId)
        {
            var api = dbContext.Apis.Single(p => p.Id == apiId);

            if (api != null)
            {
                try
                {
                    api.IsDeleted = true;
                    dbContext.Entry(api).State = System.Data.Entity.EntityState.Modified;
                    dbContext.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.Accepted, apiId));
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
                }
            }
            return(Request.CreateResponse(HttpStatusCode.Unauthorized, apiId));
        }
Ejemplo n.º 3
0
        public void Put(int id, MyApiDto value)
        {
            var api = dbContext.Apis.Single(p => p.Id == id);

            if (api != null)
            {
                api.ApiName = value.ApiName;
                api.Owner   = User.Identity.Name;
                dbContext.Entry(api).State = System.Data.Entity.EntityState.Modified;
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 4
0
 public static void LogApiRequest(int apiId, string apiUrl, IPAddress ip)
 {
     using (var db = new ApifoxContext())
     {
         db.ApiRequests.Add(new ApiRequests
         {
             ApiId  = apiId,
             ApiUrl = apiUrl,
             Ip     = ip.ToString()
         });
         db.SaveChanges();
     }
 }