Esempio n. 1
0
        public ActionResult AddNewItem(Admin_Items item, HttpPostedFileBase imgFile)
        {
            string Images = "";

            if (Request.Files.Count > 0)
            {
                int i = 0;
                HttpPostedFileBase files = Request.Files[i];
                if (files.ContentLength > 0)
                {
                    string filestoragename = Guid.NewGuid().ToString() + ".jpeg";
                    string directory       = Server.MapPath("~/images/");
                    string path            = Path.Combine(directory, filestoragename);
                    files.SaveAs(path);
                    Images = filestoragename;
                }
            }
            item.Media_Id_Img = string.IsNullOrEmpty(Images) ? "/img/default_product.png" : "/images/" + Images;
            item.Created_by   = Convert.ToString(Session["AdminId"]);
            item.Updated_by   = Convert.ToString(Session["AdminId"]);
            ItemsBLL obj = new ItemsBLL();
            bool     res = obj.InsertNewItem(item);

            return(RedirectToAction("Index", "GiftItems"));
        }
Esempio n. 2
0
        public bool InsertNewItem(Admin_Items item)
        {
            try
            {
                StreamReader   readStream;
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://" + GeneralBLL.Service_Link + "/Services/AdminService.svc/CreateNewItem");
                httpWebRequest.Method      = "POST";
                httpWebRequest.ContentType = @"application/json; charset=utf-8";

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = new JavaScriptSerializer().Serialize(item);

                    streamWriter.Write(json);
                }

                HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                readStream = new StreamReader(httpResponse.GetResponseStream());

                var serializer = new DataContractJsonSerializer(typeof(bool));

                bool obj = Convert.ToBoolean(serializer.ReadObject(readStream.BaseStream));

                return(obj);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }