public int DeleteBasketLine(BasketModel bm) { int result = DaoUtilities.NO_CHANGES; HASINBASKET b = db.HASINBASKET.Find(bm.UserId, bm.ProductId); if (b != null) { db.HASINBASKET.Remove(b); try { int saveResult = db.SaveChanges(); if (saveResult == 1) result = DaoUtilities.SAVE_SUCCESSFUL; } catch (DbUpdateConcurrencyException e) { Console.WriteLine(e.GetBaseException().ToString()); result = DaoUtilities.UPDATE_CONCURRENCY_EXCEPTION; } catch (DbUpdateException e) { Console.WriteLine(e.GetBaseException().ToString()); result = DaoUtilities.UPDATE_EXCEPTION; } catch (DbEntityValidationException e) { Console.WriteLine(e.GetBaseException().ToString()); result = DaoUtilities.ENTITY_VALIDATION_EXCEPTION; } catch (NotSupportedException e) { Console.WriteLine(e.GetBaseException().ToString()); result = DaoUtilities.UNSUPPORTED_EXCEPTION; } catch (ObjectDisposedException e) { Console.WriteLine(e.GetBaseException().ToString()); result = DaoUtilities.DISPOSED_EXCEPTION; } catch (InvalidOperationException e) { Console.WriteLine(e.GetBaseException().ToString()); result = DaoUtilities.INVALID_OPERATION_EXCEPTION; } } return result; }
/// <summary> /// Convert a basket from the database to a BasketModel /// </summary> /// <param name="b"></param> /// <returns></returns> public BasketModel ConvertBasketToBasketModel(HASINBASKET b) { BasketModel bm = new BasketModel(); if (b != null) { bm.UserId = b.USER_ID; bm.ProductId = b.PRODUCT_ID; bm.Quantity = b.QUANTITY; } else bm = null; return bm; }