public bool Exec(SqlConnection db, AuthenticatedUser au, NewProductData obj)
        {
            if (string.IsNullOrEmpty(obj.Name))
            {
                Error = new ServiceError {
                    Message = "Name is empty!"
                };
                return(false);
            }

            if (!repository.ProductExistsId(db, obj.Id))
            {
                Error = new ServiceError {
                    Message = "Id invalid!"
                };
                return(false);
            }

            var prod = repository.ProductById(db, obj.Id);

            prod.DateEdit          = DateTime.Now;
            prod.LastEditByAdminID = au.Id;
            prod.Name = obj.Name;

            repository.ProductEdit(db, prod);

            return(true);
        }
        public ActionResult <string> Token_AdminEditProduct([FromBody] NewProductData obj)
        {
            var obsolete = new List <string>
            {
                GetCacheMask_Products(obj.ProductCategoryID, obj.ProductSubCategoryID)
            };

            return(ExecuteRemoteService(obj, token: true, lstCacheCleanup: obsolete));
        }
Exemple #3
0
        public ActionResult AddProduct(NewProductData data)
        {
            try
            {
                manager.AddProduct(data);
            }
            catch (Exception e)
            {
                return(BadRequest("Can`t add new Product."));
            }

            return(Ok());
        }
        public bool Exec(SqlConnection db, AuthenticatedUser ua, NewProductData obj)
        {
            if (string.IsNullOrEmpty(obj.Name))
            {
                Error = new ServiceError {
                    Message = "Name is empty"
                };
                return(false);
            }

            if (repository.CategoryById(db, obj.ProductCategoryID) == null)
            {
                Error = new ServiceError {
                    Message = "Invalid product category"
                };
                return(false);
            }

            if (repository.SubCategoryById(db, obj.ProductSubCategoryID) == null)
            {
                Error = new ServiceError {
                    Message = "Invalid product subcategory"
                };
                return(false);
            }

            if (repository.ProductExists(db, obj.ProductCategoryID, obj.ProductSubCategoryID, obj.Name))
            {
                Error = new ServiceError {
                    Message = "Product already exists"
                };
                return(false);
            }

            IdCreated = repository.ProductAdd(db, new Product
            {
                CreatedByAdminID  = ua.Id,
                LastEditByAdminID = ua.Id,
                DateAdded         = DateTime.Now,
                DateEdit          = DateTime.Now,
                Name = obj.Name,
                ProductCategoryID    = obj.ProductCategoryID,
                ProductSubCategoryID = obj.ProductSubCategoryID
            });

            return(true);
        }
        public ActionResult <string> Token_AdminCreateProduct([FromBody] NewProductData obj)
        {
            if (!this.features.CreateProduct.Execute)
            {
                return(BadRequest(new ServiceError
                {
                    Message = this.features.CreateProduct.ErrorMessage
                }));
            }

            var tags = new List <string>
            {
                GetCacheMask_Products(obj.ProductCategoryID, obj.ProductSubCategoryID)
            };

            return(ExecuteRemoteService(obj, token: true, lstCacheCleanup: tags));
        }
Exemple #6
0
        public ActionResult <string> EditProduct([FromBody] NewProductData obj)
        {
            try
            {
                using (var db = new SqlConnection(GetDBConnectionString()))
                {
                    var service = new AdminEditProductV1(repository);

                    if (!service.Exec(db, GetCurrentAuthenticatedUser(), obj))
                    {
                        return(BadRequest(service.Error));
                    }

                    return(Ok());
                }
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new ServiceError {
                    DebugInfo = ex.ToString(), Message = _defaultError
                }));
            }
        }
Exemple #7
0
 public void ProductEdit(SqlConnection db, NewProductData obj)
 {
     throw new System.NotImplementedException();
 }
 public void ProductEdit(SqlConnection db, NewProductData obj)
 {
     db.Query(@"update [Product] set Name=@Name where Id=@Id", new { obj.Name, obj.Id });
 }
Exemple #9
0
 /// <summary>
 /// adds new product with data from addForm
 /// </summary>
 /// <param name="model"></param>
 public void AddProduct(NewProductData model)
 {
     productManager.AddProduct(model.Name, model.Price, model.InStock);
 }