コード例 #1
0
        public ValidationResult_OSC DeleteCategory(int categoryId)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    var category = (from prodCat in entity.ProductCategories
                                    where prodCat.Id == categoryId
                                    select prodCat).First();

                    entity.ProductCategories.Remove(category);
                    entity.SaveChanges();

                    result.Success = true;
                    result.Message = "Product deleted successfully";
                    return result;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }
コード例 #2
0
        public ValidationResult_OSC AddListProductImageFilePath(List<OnlineShoppingCart.Model.ProductImageInfo> lstProductImageInfo)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    foreach (var productImageInfo in lstProductImageInfo)
                    {
                        OnlineShoppingCart.DataAccess.SQL.ProductImageFilePath _product = new DataAccess.SQL.ProductImageFilePath
                        {
                            ProductId = productImageInfo.ProductId,
                            ImageFilePath = productImageInfo.ImageFilePath,
                            IsIndexImage = productImageInfo.IsIndexImage
                        };
                        entity.ProductImageFilePaths.Add(_product);
                    }
                    entity.SaveChanges();

                    result.Success = true;
                    result.Message = "Product image path information inserted successfully";
                }
                return result;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }
コード例 #3
0
        public ValidationResult_OSC AddCategory(OnlineShoppingCart.Model.ProductCategory category)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    OnlineShoppingCart.DataAccess.SQL.ProductCategory _category = new DataAccess.SQL.ProductCategory
                    {
                        Category = category.Category,
                        IsActive = category.IsActive,
                        CreatedOn = category.CreatedOn,
                        UpdatedOn = category.UpdatedOn,
                        CreatedByUserId = category.CreatedByUserID,
                        UpdatedByUserId = category.UpdatedByUserID
                    };

                    entity.ProductCategories.Add(_category);
                    entity.SaveChanges();

                    result.Success = true;
                    result.returnValue = Convert.ToString(_category.Id);
                    result.Message = "Product category inserted successfully";
                }
                return result;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }
コード例 #4
0
        public ValidationResult_OSC DeletProduct(int productId)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    var product = (from t in entity.Products
                                   where t.Id == productId
                                   select t).First();

                    entity.Products.Remove(product);
                    entity.SaveChanges();

                    result.Success = true;
                    result.Message = "Product deleted successfully";
                    return result;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }
コード例 #5
0
        // PUT api/values/5
        public ValidationResult_OSC Put([FromBody]OnlineShoppingCart.Model.Product product)
        {
            var result = new ValidationResult_OSC();
            ValidationHelper validationHelper = new ValidationHelper(ref result, ModelState);

            if (result.Success)
            {
                DAL.Product productDAL = new DAL.Product();
                result = productDAL.UpdateProduct(product);
            }
            return result;
        }
        //public Result<List<OnlineShoppingCart.Model.ProductCategory>> Get(string category)
        //{
        //    DAL.ProductCategory productCategoryDAL = new DAL.ProductCategory();
        //    return productCategoryDAL.GetCategoryList(category);
        //}
        // POST api/values
        public ValidationResult_OSC Post([FromBody]OnlineShoppingCart.Model.ProductCategory productCategory)
        {
            var result = new ValidationResult_OSC();
            ValidationHelper validationHelper = new ValidationHelper(ref result, ModelState);

            if (result.Success)
            {
                DAL.ProductCategory productDAL = new DAL.ProductCategory();
                result = productDAL.AddCategory(productCategory);
            }
            return result;
        }
コード例 #7
0
 public ValidationHelper(ref ValidationResult_OSC result, ModelStateDictionary ModelState)
 {
     if (!ModelState.IsValid)
     {
         foreach (var value in ModelState.Values)
         {
             foreach (var err in value.Errors)
             {
                 result.AddMessage(err.ErrorMessage);
             }
         }
     }
 }
コード例 #8
0
        public ValidationResult_OSC PostProductImageInfo([FromBody] List<OnlineShoppingCart.Model.ProductImageInfo> lstProductImageInfo)
        {
            var result = new ValidationResult_OSC();

            //validate that string path is not empty
            bool listNotValid = lstProductImageInfo.Any(cus => String.IsNullOrWhiteSpace(cus.ImageFilePath));
            if (listNotValid)
            {
                result.AddMessage("One or more image path are empty.");
                return result;
            }
            ProductImage productImageDAL = new ProductImage();
            result = productImageDAL.AddListProductImageFilePath(lstProductImageInfo);
            return result;
        }
コード例 #9
0
        public ValidationResult_OSC AddProduct(OnlineShoppingCart.Model.Product product)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    OnlineShoppingCart.DataAccess.SQL.Product _product = new DataAccess.SQL.Product
                    {
                        Model = product.Model,
                        ProductCode = product.ProductCode,
                        ProductName = product.ProductName,
                        ProductDescription = product.ProductDescription,
                        CategoryId = product.CategoryID,
                        Brand = product.Brand,
                        UnitPrice = product.UnitPrice,
                        SKU = product.SKU,
                        CurrentStock = product.CurrentStock,
                        IsActive = product.IsActive,
                        CreatedOn = product.CreatedOn,
                        UpdatedOn = product.UpdatedOn,
                        CreatedByUserId = product.CreatedByUserID,
                        UpdatedByUserId = product.UpdatedByUserID
                    };
                    entity.Products.Add(_product);
                    entity.SaveChanges();

                    result.Success = true;
                    result.returnValue = Convert.ToString(_product.Id);
                    result.Message = "Product inserted successfully";
                }
                return result;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }
コード例 #10
0
        public ValidationResult_OSC UpdateCategory(OnlineShoppingCart.Model.ProductCategory category)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    var _category = (from prodCat in entity.ProductCategories
                                     where prodCat.Id == category.ID
                                     select prodCat).First();

                    _category.Category = category.Category;
                    _category.IsActive = category.IsActive;
                    _category.CreatedOn = category.CreatedOn;
                    _category.UpdatedOn = category.UpdatedOn;
                    _category.CreatedByUserId = category.CreatedByUserID;
                    _category.UpdatedByUserId = category.UpdatedByUserID;

                    entity.SaveChanges();
                    result.Success = true;
                    result.Message = "Product category updated successfully";
                    return result;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }
コード例 #11
0
        public async Task<JsonResult> AddCategory(ProductCategory prodCategoryToAdd)
        {
             
            ValidationResult_OSC result = new ValidationResult_OSC();
            prodCategoryToAdd.CreatedOn = DateTime.Now.Date;
            prodCategoryToAdd.IsActive = true;
            prodCategoryToAdd.CreatedByUserID = 2;
            prodCategoryToAdd.UpdatedByUserID = 2;
            using (var client = new HttpClient())
            {
                string url = System.Configuration.ConfigurationManager.AppSettings["ProductCategoryAPI"];
                client.BaseAddress = new Uri(url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = await client.PostAsJsonAsync("api/ProductCategory/", prodCategoryToAdd);
                if (response.IsSuccessStatusCode)
                {
                    result = await response.Content.ReadAsAsync<ValidationResult_OSC>();
                    if (result.Success == true)
                        return Json(result, JsonRequestBehavior.AllowGet);
                    else
                    {
                        return Json(result, JsonRequestBehavior.AllowGet);
                    }
                     
                }

            }
            return Json(result, JsonRequestBehavior.AllowGet);
        }
コード例 #12
0
        public ValidationResult_OSC UpdateProduct(OnlineShoppingCart.Model.Product product)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    var _p = (from t in entity.Products
                              where t.Id == product.ID
                              select t).First();

                    _p.Model = product.Model;
                    _p.ProductCode = product.ProductCode;
                    _p.ProductName = product.ProductName;
                    _p.ProductDescription = product.ProductDescription;
                    _p.CategoryId = product.CategoryID;
                    _p.Brand = product.Brand;
                    _p.UnitPrice = product.UnitPrice;
                    _p.SKU = product.SKU;
                    _p.CurrentStock = product.CurrentStock;
                    _p.IsActive = product.IsActive;
                    _p.CreatedOn = product.CreatedOn;
                    _p.UpdatedOn = product.UpdatedOn;
                    _p.CreatedByUserId = product.CreatedByUserID;
                    _p.UpdatedByUserId = product.UpdatedByUserID;

                    entity.SaveChanges();
                    result.Success = true;
                    result.Message = "Product updated successfully";
                    return result;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }