public ActionResult UpLoad(ProductUploadViewModel p)
        {
            if (ModelState.IsValid)
            {
                DataTransferLayer.Accounts.User u = WebApiHelper.
                    GetUserFromServer("api/accountManager/account/search/" + User.Identity.Name, Method.GET);

                if (u != null)
                {
                    ProductApi np = new ProductApi();
                    np.Name = p.ProductName;
                    np.CategoryId = p.SelectedCat;
                    np.Location = p.SelectedPos;
                    np.Description = p.Description;
                    np.Price = decimal.Parse(p.ProductPrice);
                    np.UserId = u.Id;
                    np.ProductKey = p.ProductKey;

                    WebApiHelper.AddProductToServer("api/product/add", Method.PUT, np);

                    return RedirectToAction("UploadPicture", "ProductManager", p);
                }
                else
                {
                    FormsAuthentication.SignOut();
                    Session["role"] = null;
                    Session["UserId"] = null;
                    return RedirectToAction("Logout", "Account");
                }
                           
            }

            return View(p);
        }
예제 #2
0
        public Product(ProductApi p)
        {
            if (p != null)
            {
                Id = p.Id;
                Name = p.Name;
                Description = p.Description;
                CategoryId = p.CategoryId;
                Price = p.Price;
                Picture = p.Picture;
                PostingDate = p.PostingDate;
                Available = p.Available;
                UserId = p.UserId;
                ProductKey = p.ProductKey;
                Location = p.Location;
            }         

            Comments = new HashSet<Comment>();
            FollowProducts = new HashSet<FollowProduct>();
            ProductImages = new HashSet<ProductImage>();
            Reports = new HashSet<Report>();
        }
        public ActionResult EditProduct(ProductUploadViewModel p)
        {
            if (ModelState.IsValid)
            {
                ProductApi np = new ProductApi();
                np.Id = p.Id;
                np.Name = p.ProductName;
                np.CategoryId = p.SelectedCat;
                np.Location = p.SelectedPos;
                np.Description = p.Description;
                np.Price = decimal.Parse(p.ProductPrice);
                np.UserId = (int) Session["UserId"];
                np.ProductKey = p.ProductKey;

                WebApiHelper.EditProductOnServer("api/product/edit", Method.POST, np);

                return RedirectToAction("EditSuccessful", "ProductManager", p);
            }

            return View(p);
        }
예제 #4
0
        public static bool EditProductOnServer(string requestResource, Method method, ProductApi product)
        {
            var client = new RestClient();
            // This, of course, needs to be altered to match the
            // IP Address/Port of the server to which you are connecting
            client.BaseUrl = new Uri(ClientBase);
            var request = new RestRequest();
            // The server's Rest method will probably return something
            // other than "duckbilledPlatypi" in your case
            request.Resource = requestResource + "/"
                + product.Id + Seperator
                + product.Name + Seperator
                + product.CategoryId + Seperator
                + product.Location + Seperator
                + product.Description + Seperator
                + product.Price + Seperator
                + product.UserId + Seperator
                + product.ProductKey;
            request.Method = method;

            var response = client.Execute(request) as RestResponse;

            if (response != null
                && ((response.StatusCode == HttpStatusCode.OK)
                    && (response.ResponseStatus == ResponseStatus.Completed)))
            // It's probably not necessary to test both
            {
                return true;
            }
            else
                if (response != null)
                {
                    return false;
                }

            return false;
        }