コード例 #1
0
 public string RemoveCalculator(int calculatorId)
 {
     using (WeighUpEntities _context = new WeighUpEntities())
     {
         var calc = _context.Calculators.SingleOrDefault(x => x.CalculatorId == calculatorId);
         _context.Calculators.Remove(calc);
         var isSold = _context.SaveChanges() > 0;
         return(isSold ? $"{calc.CalculatorName} Removed successfully" : $"Removing {calc.CalculatorName} failed");
     }
 }
コード例 #2
0
 public string BuyCalculator(int BuyerId, int calculatorId)
 {
     using (WeighUpEntities _context = new WeighUpEntities())
     {
         var calc = _context.Calculators.SingleOrDefault(x => x.CalculatorId == calculatorId);
         calc.BuyerId = BuyerId;
         var isSold = _context.SaveChanges() > 0;
         return(isSold ? $"{calc.CalculatorName} sold successfully" : $"Failed to sell {calc.CalculatorName}");
     }
 }
コード例 #3
0
 public string UpdateCalculator(int calculatorId, string brand, string model, decimal price)
 {
     using (WeighUpEntities _context = new WeighUpEntities())
     {
         var calc = _context.Calculators.SingleOrDefault(x => x.CalculatorId == calculatorId);
         calc.CalculatorName = brand ?? calc.CalculatorName;
         calc.Model          = model ?? calc.Model;
         calc.Price          = price.ToString() ?? calc.Price;
         //_context.Calculators.Attach(calc);
         var isUpdated = _context.SaveChanges() > 0;
         return(isUpdated ? $"{brand} Updated successfully" : $"Removing {brand} failed");
     }
 }
コード例 #4
0
 public string AddCalculator(int sellerId, string brand, string model, decimal price)
 {
     using (WeighUpEntities _context = new WeighUpEntities())
     {
         Calculator calculator = new Calculator
         {
             CalculatorName = brand,
             Model          = model,
             Price          = price.ToString(),
             SellerId       = sellerId,
             CreateDate     = DateTime.Now
         };
         _context.Calculators.Add(calculator);
         var isSold = _context.SaveChanges() > 0;
         return(isSold ? $"{brand} added successfully" : $"Adding {brand} failed");
     }
 }