public ActionResult RecoveryFirstCategoryStatus([FromBody] FirstCategory firstCategory) { try { if (firstCategory == null || firstCategory.FirstCategoryId <= 0) { return(Ok(new { mark = "2", msg = "请求数据为空!" })); } firstCategory.Status = 1; // 改变状态 if (_firstCategoryService.ChangeFirstCategoryStatus(firstCategory)) { return(Ok(new { mark = "1", msg = "成功!" })); } return(Ok()); } catch (Exception ex) { Console.WriteLine(ex); return(Ok()); } }
public ActionResult ChangeFirstCategory([FromBody] FirstCategory firstCategory) { try { if (firstCategory == null || firstCategory.FirstCategoryId <= 0 || string.IsNullOrEmpty(firstCategory.FirstCategoryName)) { return(Ok(new { mark = "2", msg = "请求数据为空!" })); } if (_firstCategoryService.ChangeFirstCategory(firstCategory)) { return(Ok(new { mark = "1", msg = "成功!" })); } return(Ok(new { mark = "2", msg = "失败!" })); } catch (Exception ex) { Console.WriteLine(ex); return(Ok()); } }
public ActionResult AddFirstCategory([FromBody] FirstCategory firstCategory) { try { if (firstCategory == null) { return(null); } if (string.IsNullOrEmpty(firstCategory.FirstCategoryName)) { return(Ok(new { mark = "2", msg = "分类名称不可为空" })); } //初始化数据 firstCategory.Status = 1; firstCategory.CreateDate = DateTime.Now; firstCategory.UpdateDate = DateTime.Now; var fcId = _firstCategoryService.AddFirstCategory(firstCategory); return(Ok(new { mark = "1", msg = "success", fcid = fcId })); } catch (Exception ex) { Console.WriteLine(ex); return(Ok()); } }
public void DeveryScenario_Should_Work() { // Arrange var shoppingCart = new ShoppingCart(1); var category = new FirstCategory(1, "Food"); var apple = new FirstProduct(1, "Apple", 100, category); var almonds = new FirstProduct(1, "Almonds", 150, category); shoppingCart.AddProduct(apple, 3); shoppingCart.AddProduct(almonds); var campaign1 = new CampaignDiscountByPercentage(1, "Food Campaign 1", 20, category, 3); var campaign2 = new CampaignDiscountByPercentage(2, "Food Campaign 2", 50, category, 5); var campaign3 = new CampaignDiscountByAmount(3, "Food Campaign 3", 5, category, 0); var campaigns = new List <CampaignBase>() { campaign1, campaign2, campaign3 }; var coupon = new CouponDiscountByPercentage(1, 100, 10); shoppingCart.AddCoupon(coupon); var delivery = new DeliverDynamic((decimal)2.99, 5, 3); // Act shoppingCart.ApplyDiscounts(campaigns); shoppingCart.ApplayDelivery(delivery); // Assert Assert.True(shoppingCart._isCouponApplied == true && shoppingCart._isCampaignApplied == true); }
/// <summary> /// 获取大分类 /// </summary> /// <param name="firstCategory"></param> /// <param name="currentPage"></param> /// <param name="pageSize"></param> /// <returns></returns> public object GetFirstCategories(FirstCategory firstCategory, int currentPage = 1, int pageSize = 10) { try { var query = (from fc in _dataContext.FirstCategories select new FirstCategoryViewModel { FirstCategoryId = fc.FirstCategoryId, FirstCategoryName = fc.FirstCategoryName, Status = fc.Status, CreateDate = fc.CreateDate, UpdateDate = fc.UpdateDate, SecondCategoryCount = _dataContext.SecondCategories.Count(x => x.FirstCategory.FirstCategoryId == fc.FirstCategoryId), PostCount = _dataContext.PostInfos.Count(p => p.SecondCategory.FirstCategory.FirstCategoryId == fc.FirstCategoryId) }).Skip((currentPage - 1) * pageSize).Take(pageSize); if (firstCategory != null) { if (firstCategory.Status > 0) { query = query.Where(fc => fc.Status == firstCategory.Status); } if (!string.IsNullOrEmpty(firstCategory.FirstCategoryName)) { query = query.Where(fc => fc.FirstCategoryName.Contains(firstCategory.FirstCategoryName)); } } return(query); } catch (Exception ex) { throw ex; } }
public void Create_Category_ShouldWork_Tehory(int id, string title) { // Arrange // Act var test = new FirstCategory(id, title); // Assert Assert.True(test != null && test._id == id && test._title.Equals(title)); }
public void Create_Deliverye_Should_Work_Tehory(decimal fixedPrice, decimal costPerDelivery, decimal costPerProduct) { // Arrange CategoryBase category = new FirstCategory(1, "First"); // Act var test = new DeliverDynamic(fixedPrice, costPerDelivery, costPerProduct); // Assert Assert.True(test != null && test._fixedPrice == fixedPrice && test._costPerProduct == costPerProduct && test._costPerDelivery == costPerDelivery); }
public void Create_Product_With_Invalid_Value_Throw_ArgumentException_Tehory(int id, string title, decimal price) { // Arrange CategoryBase category = new FirstCategory(1, "First"); // Act // Assert Assert.Throws <ArgumentException>(() => new FirstProduct(id, title, price, category)); }
public void Create_CampaigDiscountByAmount_With_Invalid_Value_Throw_ArgumentException_Tehory(int id, string title, decimal discount, int trashold) { // Arrange CategoryBase category = new FirstCategory(1, "First"); // Act // Assert Assert.Throws <ArgumentException>(() => new CampaignDiscountByAmount(id, title, discount, category, trashold)); }
public void Create_CampaigDiscountByAmount_Should_Work_Tehory(int id, string title, decimal discount, int trashold) { // Arrange CategoryBase category = new FirstCategory(1, "First"); // Act var test = new CampaignDiscountByAmount(id, title, discount, category, trashold); // Assert Assert.True(test != null && test._id == id && test._title.Equals(title) && test._category == category); }
public void Create_Product_ShouldWork_Tehory(int id, string title, decimal price) { // Arrange CategoryBase category = new FirstCategory(1, "First"); // Act var test = new FirstProduct(id, title, price, category); // Assert Assert.True(test != null && test._id == id && test._title.Equals(title)); }
public void CalculateDiscount_For_CampaigDiscountByPercentage_Should_Work() { // Arrange CategoryBase category = new FirstCategory(1, "First"); var test = new CampaignDiscountByPercentage(1, "test", 1, category, 3); // Act test.CalculateDiscount(null); // Assert Assert.True(test._calculatedDiscountAmount == 0); }
/// <summary> /// 根据ID获取大分类 /// </summary> /// <param name="firstCategory"></param> /// <returns></returns> public FirstCategory GetFirstCategory(FirstCategory firstCategory) { try { return(_dataContext.FirstCategories .FirstOrDefault(fc => fc.FirstCategoryId == firstCategory.FirstCategoryId)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 添加大分类 /// </summary> /// <param name="firstCategory"></param> /// <returns></returns> public int AddFirstCategory(FirstCategory firstCategory) { try { _dataContext.Add(firstCategory); return(_dataContext.SaveChanges() > 0 ? firstCategory.FirstCategoryId : 0); } catch (Exception ex) { throw ex; } }
public void AddProduct_ShouldWork() { // Arrange var test = new ShoppingCart(1); var category = new FirstCategory(1, "test"); var product = new FirstProduct(1, "test", 1, category); // Act test.AddProduct(product); // Assert Assert.True(test._cartCoupons != null && test._selectedProducts.Contains(product)); }
public void CalculateSumPriceOfProductList_Shold_Work() { // Arrange var products = new List <ProductBase>(); var category = new FirstCategory(1, "test"); var product = new FirstProduct(1, "test", 10, category); products.Add(product); // Act var test_Price = Helper.CalculateSumPriceOfProductList(products); // Assert Assert.True(test_Price == 10); }
public ActionResult GetFirstCategory(FirstCategory firstCategory) { try { _firstCategoryService.GetFirstCategory(firstCategory); return(Ok()); } catch (Exception e) { Console.WriteLine(e); } return(Ok()); }
public void DeleteProduct_ShouldWork_Theory(int id, int count) { // Arrange var test = new ShoppingCart(1); var category = new FirstCategory(1, "test"); var product = new FirstProduct(1, "test", 1, category); test.AddProduct(product); // Act test.DeleteProduct(id, count); // Assert Assert.True(test._selectedProducts.Count == 1); }
public void ApplyCampaigns_Should_Work() { // Arrange var shoppingCart = new ShoppingCart(1); var category = new FirstCategory(1, "test"); var product = new FirstProduct(1, "test", 100, category); var product2 = new FirstProduct(1, "test", 100, category); var product3 = new FirstProduct(1, "test", 100, category); shoppingCart.AddProduct(product); shoppingCart.AddProduct(product2); shoppingCart.AddProduct(product3); // Act shoppingCart.ApplyCampaigns(new List <CampaignBase>()); // Assert Assert.True(shoppingCart._isCampaignApplied == true); }
public void CalculateDiscount_For_CampaigDiscountByPercentage_Should_Work_AndApply_Discount() { // Arrange CategoryBase category = new FirstCategory(1, "First"); var products = new List <ProductBase>(); products.Add(new FirstProduct(1, "test", 10, category)); products.Add(new FirstProduct(1, "test", 10, category)); products.Add(new FirstProduct(1, "test", 10, category)); var test = new CampaignDiscountByPercentage(1, "test", 10, category, 3); // Act test.CalculateDiscount(products); // Assert Assert.True(test._calculatedDiscountAmount == 3); }
public void AddCoupon_Should_Work() { // Arrange var shoppingCart = new ShoppingCart(1); var category = new FirstCategory(1, "test"); var product = new FirstProduct(1, "test", 100, category); var product2 = new FirstProduct(1, "test", 100, category); var product3 = new FirstProduct(1, "test", 100, category); shoppingCart.AddProduct(product); shoppingCart.AddProduct(product2); shoppingCart.AddProduct(product3); var coupon = new CouponDiscountByAmount(1, 100, 20); shoppingCart.AddCoupon(coupon); // Act shoppingCart.ApplyCoupon(); // Assert Assert.True(shoppingCart._isCouponApplied == true); }
/// <summary> /// 修改大分类状态 /// </summary> /// <returns></returns> public bool ChangeFirstCategoryStatus(FirstCategory firstCategory) { try { if (firstCategory == null || firstCategory.FirstCategoryId <= 0) { return(false); } var fc = _dataContext.FirstCategories.FirstOrDefault(f => f.FirstCategoryId == firstCategory.FirstCategoryId); if (fc == null) { return(false); } fc.Status = firstCategory.Status; fc.UpdateDate = DateTime.Now; _dataContext.Update(fc); return(_dataContext.SaveChanges() > 0 ? true : false); } catch (Exception ex) { Console.WriteLine(ex); throw ex; } }
/// <summary> /// 更新大分类 /// </summary> /// <param name="firstCategory"></param> /// <returns></returns> public bool ChangeFirstCategory(FirstCategory firstCategory) { try { if (firstCategory == null || firstCategory.FirstCategoryId <= 0) { return(false); } var fc = _dataContext.FirstCategories.FirstOrDefault(f => f.FirstCategoryId == firstCategory.FirstCategoryId); if (fc == null) { return(false); } fc.FirstCategoryName = firstCategory.FirstCategoryName; // 更新名称 fc.UpdateDate = DateTime.Now; // 更新时间 _dataContext.Update(fc); return(_dataContext.SaveChanges() > 0 ? true : false); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取大分类总数 /// </summary> /// <returns></returns> public int GetTotalCountOfFristCategories(FirstCategory firstCategory) { try { if (firstCategory == null) { return(0); } var query = _dataContext.FirstCategories.Where(x => 1 == 1); if (firstCategory.Status > 0) { query = query.Where(fc => fc.Status == firstCategory.Status); } if (!string.IsNullOrEmpty(firstCategory.FirstCategoryName)) { query = query.Where(fc => fc.FirstCategoryName.Contains(firstCategory.FirstCategoryName)); } return(query.Count()); } catch (Exception ex) { throw ex; } }
static void Main(string[] args) { var shoppingCart = new ShoppingCart(1); var category = new FirstCategory(1, "Food"); var apple = new FirstProduct(1, "Apple", 100, category); var almonds = new FirstProduct(2, "Almonds", 150, category); shoppingCart.AddProduct(apple, 3); shoppingCart.AddProduct(almonds); var campaign1 = new CampaignDiscountByPercentage(1, "Food Campaign 1", 20, category, 3); var campaign2 = new CampaignDiscountByPercentage(2, "Food Campaign 2", 50, category, 5); var campaign3 = new CampaignDiscountByAmount(3, "Food Campaign 3", 5, category, 0); var campaigns = new List <CampaignBase>() { campaign1, campaign2, campaign3 }; var coupon = new CouponDiscountByPercentage(1, 100, 10); shoppingCart.AddCoupon(coupon); var delivery = new DeliverDynamic((decimal)2.99, 5, 3); // Act shoppingCart.ApplyDiscounts(campaigns); shoppingCart.ApplayDelivery(delivery); Console.WriteLine("Indirim öncesi Tutar : " + shoppingCart.SumOfProducts); Console.WriteLine("Indirim sonrası Tutar : " + shoppingCart.TotalAmountAfterDiscount); Console.WriteLine("Kullanılan Kopon : " + shoppingCart._couponTotalDiscount); Console.WriteLine("Kampanya indirimi : " + shoppingCart._campaignMaxDiscount); var campaignsHasMaxDiscountByCategory = from c in shoppingCart._selectedProducts group c by c._category into ctg select ctg; foreach (var item in campaignsHasMaxDiscountByCategory) { var appliedCampaign = shoppingCart._appliedCampaigns.FirstOrDefault(x => x._category == item.Key); Console.Write(item.First()._category._title); if (appliedCampaign != null) { Console.Write(" uygulanan kampanya : " + appliedCampaign._calculatedDiscountAmount); } Console.WriteLine(); var produsctTypes = from c in item group c by c._id into prd select prd; foreach (var item2 in produsctTypes) { Console.WriteLine(item2.First()._title + " " + item2.Count() + " " + item2.Sum(x => x._price)); } } Console.WriteLine("Kargo maliyeti : " + shoppingCart._deliveryCost); Console.WriteLine("Toplam Maliyet Tutarı : " + shoppingCart.TotalySumAffterDelivery); Console.ReadLine(); }