Example #1
0
        public ActionResult Delete(int id, GridEditMode mode, GridButtonType type)
        {
            //Find a product with ProductID equal to the id action parameter
            EditableProduct product = SessionProductRepository.One(p => p.ProductID == id);

            RouteValueDictionary routeValues;

            if (product == null)
            {
                //A product with the specified id does not exist - redisplay the grid

                //GridRouteValues() is an extension method which returns the
                //route values defining the grid state - current page, sort expression, filter etc.
                routeValues = this.GridRouteValues();
                // add the editing mode to the route values
                routeValues.Add("mode", mode);
                // add button type to the route values
                routeValues.Add("type", type);

                return(RedirectToAction("EditingServerSide", routeValues));
            }

            //Delete the record
            SessionProductRepository.Delete(product);

            routeValues = this.GridRouteValues();
            // add the editing mode to the route values
            routeValues.Add("mode", mode);
            // add button type to the route values
            routeValues.Add("type", type);

            //Redisplay the grid
            return(RedirectToAction("EditingServerSide", routeValues));
        }
        private new_contract_plan_productBase UpdateContract(EditableProduct editProduct)
        {
            var product = Db.new_contract_plan_productBase.FirstOrDefault(prod => prod.new_contract_plan_productId == editProduct.ProductId);

            if (product != null)
            {
                product.new_service_1_quarter    = editProduct.Service1Quarter; //save 2 times same values and look if second update contains values from first
                product.new_service_2_quarter    = editProduct.Service2Quarter;
                product.new_service_3_quarter    = editProduct.Service3Quarter;
                product.new_service_4_quarter    = editProduct.Service4Quarter;
                product.new_consulting_1_quarter = editProduct.Consult1Quarter;
                product.new_consulting_2_quarter = editProduct.Consult2Quarter;
                product.new_consulting_3_quarter = editProduct.Consult3Quarter;
                product.new_consulting_4_quarter = editProduct.Consult4Quarter;
                product.new_service_year         = editProduct.NewServiceYear;                                                                                              //переходящие сервис
                product.new_consulting_year      = editProduct.NewConsultYear;                                                                                              //переходящие консалтинг

                product.new_year_sum = editProduct.NewServiceYear + editProduct.NewConsultYear;                                                                             //переходящие контракты сумма год

                product.new_product_sum_service    = editProduct.Service1Quarter + editProduct.Service2Quarter + editProduct.Service3Quarter + editProduct.Service4Quarter; // сервис год
                product.new_product_sum_consulting = editProduct.Consult1Quarter + editProduct.Consult2Quarter + editProduct.Consult3Quarter + editProduct.Consult4Quarter; //консалт год
            }

            return(product);
        }
Example #3
0
        public ActionResult InlineEditingUpdatePartial([ModelBinder(typeof(DevExpressEditorsBinder))] EditableProduct product, bool forceUpdate = false)
        {
            if (ModelState.IsValid)
            {
                try {
                    bool dbCheckResult = false;                     //checking is failed, for demo only

                    bool canUpdate = dbCheckResult || forceUpdate;
                    ViewData["canUpdate"] = canUpdate;
                    if (canUpdate)
                    {
                        //Update is not allowed in online demos
                        //NorthwindDataProvider.UpdateProduct(product);
                    }
                    else
                    {
                        ViewData["editedRowKey"] = product.ProductID;
                    }
                }
                catch (Exception e) {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }

            return(PartialView("GridView", NorthwindDataProvider.GetEditableProducts()));
        }
        public ActionResult Insert(GridEditMode mode, GridButtonType type)
        {
            ViewData["mode"] = mode;
            ViewData["type"] = type;

            //Create a new instance of the EditableProduct class.
            EditableProduct product = new EditableProduct();

            //Perform model binding (fill the product properties and validate it).
            if (TryUpdateModel(product))
            {
                //The model is valid - insert the product and redisplay the grid.
                SessionProductRepository.Insert(product);

                //GridRouteValues() is an extension method which returns the
                //route values defining the grid state - current page, sort expression, filter etc.
                RouteValueDictionary routeValues = this.GridRouteValues();
                // add the editing mode to the route values
                routeValues.Add("mode", mode);

                return RedirectToAction("EditingServerSide", routeValues);
            }

            //The model is invalid - render the current view to show any validation errors
            return View("EditingServerSide", SessionProductRepository.All());
        }
        // GET api/<controller>/5
        public EditableProduct Get(int id)
        {
            var userId = ((ClaimsPrincipal)this.User).FindFirst(ClaimTypes.NameIdentifier).Value;

            if (HttpContext.Current.Cache["Product" + id] != null)
            {
                return((EditableProduct)HttpContext.Current.Cache["Product" + id]);
            }
            using (Assignment4Context context = new Assignment4Context())
            {
                Product product  = context.Products.Find(id);
                var     eProduct = new EditableProduct {
                    IsJoinable = false, IsEditable = false, Version = product.Timestamp, Id = product.Id, AddedDate = product.AddedDate, ApplicationUserId = product.ApplicationUserId, Payable = product.Payable, Description = product.Description, Name = product.Name
                };
                HttpContext.Current.Cache["Product" + id] = eProduct;
                if (User.IsInRole("Admin") || (product.ApplicationUserId == userId))
                {
                    eProduct.IsEditable = true;
                    eProduct.IsJoinable = true;
                }
                if (User.IsInRole("Seeker") || (product.ApplicationUserId == userId))
                {
                    eProduct.IsEditable = false;
                    eProduct.IsJoinable = true;
                }
                if (User.IsInRole("Leader") || (product.ApplicationUserId == userId))
                {
                    eProduct.IsEditable = true;
                    eProduct.IsJoinable = false;
                }
                return(eProduct);
            }
        }
Example #6
0
        public ActionResult Save(int id, GridEditMode mode, GridButtonType type)
        {
            ViewData["mode"] = mode;
            ViewData["type"] = type;

            //Create a new instance of the EditableProduct class and set its ProductID property.
            EditableProduct product = new EditableProduct
            {
                ProductID = id
            };

            //Perform model binding (fill the product properties and validate it).
            if (TryUpdateModel(product))
            {
                //The model is valid - update the product and redisplay the grid.
                SessionProductRepository.Update(product);

                //GridRouteValues() is an extension method which returns the
                //route values defining the grid state - current page, sort expression, filter etc.
                RouteValueDictionary routeValues = this.GridRouteValues();
                // add the editing mode to the route values
                routeValues.Add("mode", mode);

                return(RedirectToAction("EditingServerSide", routeValues));
            }

            //The model is invalid - render the current view to show any validation errors
            return(View("EditingServerSide", SessionProductRepository.All()));
        }
Example #7
0
        public ActionResult ColumnSettings_Delete(int id)
        {
            //Find a product with ProductID equal to the id action parameter
            EditableProduct product = SessionProductRepository.One(p => p.ProductID == id);

            RouteValueDictionary routeValues;

            if (product == null)
            {
                //A product with the specified id does not exist - redisplay the grid

                //GridRouteValues() is an extension method which returns the
                //route values defining the grid state - current page, sort expression, filter etc.
                routeValues = this.GridRouteValues();

                return(RedirectToAction("ColumnSettings", routeValues));
            }

            //Delete the record
            SessionProductRepository.Delete(product);

            routeValues = this.GridRouteValues();

            //Redisplay the grid
            return(RedirectToAction("ColumnSettings", routeValues));
        }
    public static void DeleteProduct(int productID)
    {
        EditableProduct product = GetEditableProduct(productID);

        if (product != null)
        {
            GetEditableProducts().Remove(product);
        }
    }
Example #9
0
        public ActionResult _SaveAjaxEditing(int id)
        {
            EditableProduct product = SessionProductRepository.One(p => p.ProductID == id);

            TryUpdateModel(product);

            SessionProductRepository.Update(product);

            return(View(new GridModel(SessionProductRepository.All())));
        }
    public static void InsertProduct(EditableProduct product)
    {
        EditableProduct editProduct = new EditableProduct();

        editProduct.ProductID       = GetNewEditableProductID();
        editProduct.ProductName     = product.ProductName;
        editProduct.CategoryID      = product.CategoryID;
        editProduct.QuantityPerUnit = product.QuantityPerUnit;
        editProduct.UnitPrice       = product.UnitPrice;
        editProduct.UnitsInStock    = product.UnitsInStock;
        editProduct.Discontinued    = product.Discontinued;
        GetEditableProducts().Add(editProduct);
    }
Example #11
0
        public ActionResult _DeleteAjaxEditing(int id)
        {
            //Find a customer with ProductID equal to the id action parameter
            EditableProduct product = SessionProductRepository.One(p => p.ProductID == id);

            if (product != null)
            {
                //Delete the record
                SessionProductRepository.Delete(product);
            }

            //Rebind the grid
            return(View(new GridModel(SessionProductRepository.All())));
        }
    public static void UpdateProduct(EditableProduct product)
    {
        EditableProduct editProduct = GetEditableProduct(product.ProductID);

        if (editProduct != null)
        {
            editProduct.ProductName     = product.ProductName;
            editProduct.CategoryID      = product.CategoryID;
            editProduct.QuantityPerUnit = product.QuantityPerUnit;
            editProduct.UnitPrice       = product.UnitPrice;
            editProduct.UnitsInStock    = product.UnitsInStock;
            editProduct.Discontinued    = product.Discontinued;
        }
    }
Example #13
0
        private void InsertContract(EditableProduct editContract, IList <new_contract_plan_productBase> dataContextModelContracts)
        {
            var dataContextModelContract = new new_contract_plan_productBase();

            //initialize childs for null reference errors
            dataContextModelContract.new_d_product_groupsBase  = new new_d_product_groupsBase();
            dataContextModelContract.new_d_product_catalogBase = new new_d_product_catalogBase();

            dataContextModelContract.new_contract_plan_productId        = Guid.NewGuid(); //todo check if EF or db add guid automatically
            dataContextModelContract.new_d_product_groupsBase.new_name  = editContract.ProductGroupProduct;
            dataContextModelContract.new_d_product_catalogBase.new_name = editContract.Product;
            dataContextModelContract.new_service_1_quarter    = editContract.Service1Quarter;
            dataContextModelContract.new_consulting_1_quarter = editContract.Consult1Quarter;
            Db.new_contract_plan_productBase.ToList().Add(dataContextModelContract);
        }
        public ActionResult _InsertAjaxEditing()
        {
            //Create a new instance of the EditableProduct class.
            EditableProduct product = new EditableProduct();

            //Perform model binding (fill the product properties and validate it).
            if (TryUpdateModel(product))
            {
                //The model is valid - insert the product.
                SessionProductRepository.Insert(product);
            }

            //Rebind the grid
            return View(new GridModel(SessionProductRepository.All()));
        }
Example #15
0
        public ActionResult _InsertAjaxEditing()
        {
            //Create a new instance of the EditableProduct class.
            EditableProduct product = new EditableProduct();

            //Perform model binding (fill the product properties and validate it).
            if (TryUpdateModel(product))
            {
                //The model is valid - insert the product.
                SessionProductRepository.Insert(product);
            }

            //Rebind the grid
            return(View(new GridModel(SessionProductRepository.All())));
        }
Example #16
0
        public void Editable()
        {
            var banana = new EditableProduct
            {
                Name  = "Banana",
                Price = new decimal(2.5)
            };

            banana.BeginEdit();
            banana.Name  = "Apple";
            banana.Price = 7;
            banana.CancelEdit();

            Assert.AreEqual("Banana", banana.Name);
            Assert.AreEqual(2.5, banana.Price);
        }
Example #17
0
        // GET api/<controller>/5
        public EditableProduct Get(int id)
        {
            var userId = ((ClaimsPrincipal)this.User).FindFirst(ClaimTypes.NameIdentifier).Value;

            using (Assignment4Context context = new Assignment4Context())
            {//add payable
                var             product  = context.Products.Find(id);
                EditableProduct eProduct = new EditableProduct {
                    AddedDate = product.AddedDate, ApplicationUserId = product.ApplicationUserId, Description = product.Description, Id = product.Id, Name = product.Name, Payable = product.Payable, IsEditable = false, Version = product.Timestamp
                };
                if (User.IsInRole("Admin") || (product.ApplicationUserId == userId))
                {
                    eProduct.IsEditable = true;
                }
                return(eProduct);
            }
        }
        public ActionResult EditTemplate(EditableProduct product)
        {
            if (product.ProductID == 0)
            {
                product.ProductID    = 1;
                product.ProductName  = "Chai";
                product.UnitsInStock = 39;
                product.UnitPrice    = 18.00m;
                product.LastSupply   = DateTime.Today;
            }
            else
            {
                ViewData["product"] = product;
            }

            return(View(product));
        }
Example #19
0
        public ActionResult ColumnSettings_Save(int id)
        {
            //Create a new instance of the EditableProduct class and set its ProductID property.
            EditableProduct product = new EditableProduct
            {
                ProductID = id
            };

            //Perform model binding (fill the product properties and validate it).
            if (TryUpdateModel(product))
            {
                //The model is valid - update the product and redisplay the grid.
                SessionProductRepository.Update(product);

                //GridRouteValues() is an extension method which returns the
                //route values defining the grid state - current page, sort expression, filter etc.
                RouteValueDictionary routeValues = this.GridRouteValues();

                return(RedirectToAction("ColumnSettings", routeValues));
            }

            //The model is invalid - render the current view to show any validation errors
            return(View("ColumnSettings", SessionProductRepository.All()));
        }
        public HttpResponseMessage Post([FromBody] EditableProduct value)
        {
            try
            {
                var userId = ((ClaimsPrincipal)this.User).FindFirst(ClaimTypes.NameIdentifier).Value;
                using (Assignment4Context context = new Assignment4Context())
                {
                    if (value.Id == 0 && !User.IsInRole("Seeker"))
                    {
                        Product newProduct = context.Products.Create();
                        newProduct.Name              = value.Name;
                        newProduct.AddedDate         = DateTime.Now;
                        newProduct.ApplicationUserId = userId;
                        newProduct.Description       = value.Description;
                        newProduct.Id      = value.Id;
                        newProduct.Payable = value.Payable;
                        //newProduct.JoinedMemberList = value.JoinedMemberList;
                        context.Products.Add(newProduct);
                        context.SaveChanges();
                        HttpContext.Current.Cache.Remove("ProductList");
                        return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "Product Added." }));
                    }
                    else if (User.IsInRole("Seeker"))
                    {
                        var productMemberShip = context.ProductMembership.Create();
                        var product           = context.Products.Find(value.Id);
                        //product.JoinedMemberList = product.JoinedMemberList.Union
                        //    (User.Identity.Name.ToList());
                        //product.JoinedMemberList += userId;
                        productMemberShip.ProductId = value.Id;
                        //productMemberShip.Name = value.Name;  // project title
                        productMemberShip.UserId = User.Identity.Name; // user email
                        context.ProductMembership.Add(productMemberShip);
                        context.SaveChanges();
                        HttpContext.Current.Cache.Remove("ProductList");

                        //return Request.CreateResponse(HttpStatusCode.OK, new { success = false, message = "Seeker Can't add project" });
                        return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "You have joined this project." }));
                    }
                    else
                    {
                        var product = context.Products.Find(value.Id);
                        if (User.IsInRole("Admin") || (product.ApplicationUserId == userId))
                        {
                            product.Name              = value.Name;
                            product.AddedDate         = DateTime.Now;
                            product.ApplicationUserId = userId;
                            product.Description       = value.Description;
                            product.Id      = value.Id;
                            product.Payable = value.Payable;
                            // product.JoinedMemberList = value.JoinedMemberList;
                            context.SaveChanges();
                            HttpContext.Current.Cache.Remove("ProductList");
                            return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "Product Updated." }));
                        }
                    }
                }
                return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, message = "Product not added/updated." }));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, message = "Error Occurred. Scary Details:" + e.Message }));
            }
        }
Example #21
0
        public void Editable()
        {
            var banana = new EditableProduct
            {
                Name = "Banana",
                Price = new decimal(2.5)
            };

            banana.BeginEdit();
            banana.Name = "Apple";
            banana.Price = 7;
            banana.CancelEdit();

            Assert.AreEqual("Banana", banana.Name);
            Assert.AreEqual(2.5, banana.Price);
        }
    public static int GetNewEditableProductID()
    {
        EditableProduct lastProduct = (from product in GetEditableProducts() select product).Last();

        return((lastProduct != null) ? lastProduct.ProductID + 1 : 0);
    }