Ejemplo n.º 1
0
        public JsonResult InsertSection()
        {
            Int32 retval = 0;

            try
            {
                var resolveRequest = HttpContext.Request;
                resolveRequest.InputStream.Seek(0, System.IO.SeekOrigin.Begin);
                string jsonString = new System.IO.StreamReader(resolveRequest.InputStream).ReadToEnd();
                //deserialse
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string sectioName = serializer.Deserialize <string>(jsonString);
                if (!string.IsNullOrEmpty(sectioName))
                {
                    using (Artwork_App.ViewModels.SectionsViewModel SectionsViewModel = new ViewModels.SectionsViewModel())
                    {
                        SectionsViewModel.SectionName = sectioName;
                        retval = SectionsViewModel.Insert(SectionsViewModel);



                        return(new JsonResult
                        {
                            Data = new { Data = retval, Success = true, ErrorMessage = "" },
                            ContentEncoding = System.Text.Encoding.UTF8,
                            JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(new JsonResult
                {
                    Data = new { Data = retval, Success = true, ErrorMessage = ex.Message },
                    ContentEncoding = System.Text.Encoding.UTF8,
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            return(new JsonResult
            {
                Data = new { Data = retval, Success = false, ErrorMessage = "" },
                ContentEncoding = System.Text.Encoding.UTF8,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Ejemplo n.º 2
0
        public JsonResult DoesSectionExist()
        {
            Int32 sectionCount = 0;

            try
            {
                var resolveRequest = HttpContext.Request;
                resolveRequest.InputStream.Seek(0, System.IO.SeekOrigin.Begin);
                string jsonString = new System.IO.StreamReader(resolveRequest.InputStream).ReadToEnd();
                //deserialse
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string sectioName = serializer.Deserialize <string>(jsonString);
                if (!string.IsNullOrEmpty(sectioName))
                {
                    using (Artwork_App.ViewModels.SectionsViewModel SectionsViewModel = new ViewModels.SectionsViewModel())
                    {
                        sectionCount = SectionsViewModel.GetData().Where(x => x.SectionName == sectioName).Count();


                        return(new JsonResult
                        {
                            Data = new { Data = sectionCount, Success = true, ErrorMessage = "" },
                            ContentEncoding = System.Text.Encoding.UTF8,
                            JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(new JsonResult
            {
                Data = new { Data = sectionCount, Success = true, ErrorMessage = "" },
                ContentEncoding = System.Text.Encoding.UTF8,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }