public HttpResponseMessage Getarticles(int id)
        {
            clsArticles objArticle = new clsArticles();

            try
            {
                objArticle = (from a in db.articles
                              where (a.id == id)
                              select new clsArticles()
                {
                    id = a.id,
                    name = a.name,
                    description = a.description,
                    total_in_shelf = a.total_in_shelf,
                    total_in_vault = a.total_in_vault,
                    store_id = a.store_id
                }).FirstOrDefault <clsArticles>();


                if (objArticle == null)
                {
                    objError = objResponse.responseError(HttpStatusCode.NotFound);
                    return(Request.CreateResponse(HttpStatusCode.NotFound, objError, Configuration.Formatters.JsonFormatter));
                }

                objResponseArticles = objResponse.responseArticleSuccess(objArticle, articlesTotal());
                return(Request.CreateResponse(HttpStatusCode.OK, objResponseArticles, Configuration.Formatters.JsonFormatter));
            }
            catch (Exception ex)
            {
                objError = objResponse.responseError(HttpStatusCode.BadRequest);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, objError, Configuration.Formatters.JsonFormatter));
            }
        }
Exemplo n.º 2
0
        public async Task <bool> saveArticle(clsArticles article)
        {
            bool result = false;

            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Baseurl);
                    client.DefaultRequestHeaders.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    HttpResponseMessage Res = await client.PutAsJsonAsync(String.Format("/services/articles/{0}", article.id), article);

                    if (Res.IsSuccessStatusCode)
                    {
                        var EmpResponse = Res.Content.ReadAsStringAsync().Result;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(result);
        }
Exemplo n.º 3
0
        public async Task <clsArticles> getArticleByID(int?id)
        {
            clsArticles Articles = new clsArticles();

            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Baseurl);
                    client.DefaultRequestHeaders.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    HttpResponseMessage Res = await client.GetAsync(String.Format("services/articles/{0}", id));

                    if (Res.IsSuccessStatusCode)
                    {
                        var EmpResponse          = Res.Content.ReadAsStringAsync().Result;
                        ResponseArticles account = JsonConvert.DeserializeObject <ResponseArticles>(EmpResponse);
                        Articles = JsonConvert.DeserializeObject <clsArticles>(account.articles.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Articles);
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Delete(int?id)
        {
            clsArticles Articles = new clsArticles();

            Articles = await getArticleByID(id);

            return(View(Articles));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Edit(int?id)
        {
            clsArticles      Articles = new clsArticles();
            List <clsStores> lsStores = new List <clsStores>();

            lsStores = await getFillStore();

            Articles = await getArticleByID(id);

            return(View(Articles));
        }
Exemplo n.º 6
0
    public void GetArticleInformation()
    {
        objArticles = new clsArticles();
        DataSet dsArticle = objArticles.GetArticleInformation();

        if (dsArticle.Tables[0].Rows.Count > 0)
        {
            // ViewState["ArticleContent"] = dsArticle.Tables[0].Rows[0]["ContentOfArticle"];
            // ViewState["FileName"] = dsArticle.Tables[0].Rows[0]["FileName"];
            ViewState["dsArticle"] = dsArticle;
            grvArticles.DataSource = dsArticle.Tables[0];
            grvArticles.DataBind();
        }
    }
Exemplo n.º 7
0
        public async Task <ActionResult> Edit(clsArticles article)
        {
            List <clsStores> lsStores = new List <clsStores>();
            bool             result   = false;

            if (!ModelState.IsValid)
            {
                lsStores = await getFillStore();

                return(View(article));
            }
            result = await saveArticle(article);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 8
0
    public void InsertNewArticles()
    {
        objArticles          = new clsArticles();
        objArticles.Title    = txtTitle.Text.Trim();
        objArticles.Content  = (byte[])Session["DocFileContent"];
        objArticles.FileName = Session["DocFileName"].ToString();
        int i = objArticles.InsertNewArticle();

        if (i > 0)
        {
            Page.RegisterClientScriptBlock("admin", "<script>alert('Article Posted')</script>");
        }
        else
        {
            Page.RegisterClientScriptBlock("Admin", "<script>alert('Bad Server Request')</script>");
        }
    }