public bool UpdateStatus(long shoppingCartId, ShoppingCartStatus shoppingStatus) { //using (var conn = new SqlConnection(connectionString)) using (var conn = new NpgsqlConnection(connectionString)) { using (var transaction = conn.BeginTransaction()) { conn.Open(); try { var cartStatusEnum = (byte)shoppingStatus; DynamicParameters parameters = new DynamicParameters(); parameters.Add("@ShoppingCartId", shoppingCartId, DbType.Int64); parameters.Add("@CartStatus", cartStatusEnum, DbType.Byte); conn.QueryFirstOrDefault <SalesOrder>("UPDATE ShoppingCart SET CartStatus = @CartStatus WHERE Id = @ShoppingCartId", parameters, transaction); transaction.Commit(); return(true); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); transaction.Rollback(); return(false); } } } }
private void SeedShoppingCarts(BookstoreContext context) { var shoppingCartStatus = new ShoppingCartStatus() { ShoppingCartStatusDescription = "Created" }; var rand = new Random(); var books = context.Books .OrderBy(b => b.Id) .Skip(rand.Next(1, 100)) .Take(5) .ToList(); var user = context.Users.FirstOrDefault(); var shoppingCart = new ShoppingCart() { Books = books, ShoppingCartStatus = shoppingCartStatus, User = user }; context.ShoppingCarts.Add(shoppingCart); context.SaveChanges(); }
public ShoppingCartState(ShoppingCartState state) : base(state) { CustomerId = state.CustomerId; CreatedAm = state.CreatedAm; Active = state.Active; ShoppingCartStatus = state.ShoppingCartStatus; }
public bool UpdateStatus(long shoppingCartId, ShoppingCartStatus shoppingStatus) { if (_shoppingCartRepository.Select(shoppingCartId) == null) { throw new ArgumentException($"Carrinho não encontrado : {shoppingCartId}"); } return(_shoppingCartRepository.UpdateStatus(shoppingCartId, shoppingStatus)); }
public ShoppingCartContent(ShoppingCartId id, SalesPointId salesPointId, ViewPointId viewPointId, SalesPersonId salesPersonId, CustomerId customerId, ShoppingCartStatus status) : this(id, salesPointId, viewPointId, salesPersonId, customerId, status, null) { }
public static bool Equals(ShoppingCartContent?left, ShoppingCartContent?right) { bool result = ShoppingCartId.Equals(left?.Id, right?.Id); result &= (result ? SalesPointId.Equals(left?.SalesPointId, right?.SalesPointId) : false); result &= (result ? ViewPointId.Equals(left?.ViewPointId, right?.ViewPointId) : false); result &= (result ? SalesPersonId.Equals(left?.SalesPersonId, right?.SalesPersonId) : false); result &= (result ? CustomerId.Equals(left?.CustomerId, right?.CustomerId) : false); result &= (result ? ShoppingCartStatus.Equals(left?.Status, right?.Status) : false); result &= (result ? (left?.Items.SequenceEqual(right?.Items)).GetValueOrDefault() : false); return(result); }
/// <summary> /// Creates a new shopping cart instance. /// </summary> /// <param name="id">The unique id of the shopping cart.</param> /// <param name="status">The status of the shopping cart.</param> /// <param name="customerId">The unique id of the customer the shopping cart belongs to.</param> /// <param name="salesPersonId">The unique id of the corresponding sales person.</param> /// <param name="salesPointId">The unique id of the corresponding sales point.</param> /// <param name="viewPointId">The unique id of the corresponding view point.</param> /// <returns>An <see cref="IShoppingCart"/> instance with the specified attributes.</returns> public IShoppingCart CreateShoppingCart(string id, ShoppingCartStatus status, string customerId = "", string salesPersonId = "", string salesPointId = "", string viewPointId = "") { var shoppingCart = new ShoppingCart() { Id = TextConverter.EscapeInvalidXmlChars(id), Status = status.ToString(), CustomerId = TextConverter.EscapeInvalidXmlChars(customerId), SalesPersonId = TextConverter.EscapeInvalidXmlChars(salesPersonId), SalesPointId = TextConverter.EscapeInvalidXmlChars(salesPointId), ViewPointId = TextConverter.EscapeInvalidXmlChars(viewPointId), }; return(shoppingCart); }
public ShoppingCartContent(ShoppingCartId id, SalesPointId salesPointId, ViewPointId viewPointId, SalesPersonId salesPersonId, CustomerId customerId, ShoppingCartStatus status, IEnumerable <ShoppingCartItem>?items) { this.Id = id; this.SalesPointId = salesPointId; this.ViewPointId = viewPointId; this.SalesPersonId = salesPersonId; this.CustomerId = customerId; this.Status = status; if (items is not null) { this.Items.AddRange(items); } }
public bool UpdateStatus(long shoppingCartId, ShoppingCartStatus shoppingStatus) { return(_shoppingCartBusiness.UpdateStatus(shoppingCartId, shoppingStatus)); }
public record ShoppingCartInitializedWithStatus( Guid ShoppingCartId, Client Client, ShoppingCartStatus Status );
public record ShoppingCartInitialized( Guid ShoppingCartId, Guid ClientId, // Adding new not required property as nullable ShoppingCartStatus Status = ShoppingCartStatus.Initialized );
public static ISpecification <ShoppingCart> IsInStatus(ShoppingCartStatus status) { return(new Specification <ShoppingCart>(x => x.StateModel.ShoppingCartStatus == status)); }
public void ReturnCorrectValue_WhenInvokedWithCorrectParams() { var unitOfWorkMock = new Mock <IUnitOfWork>(); var mapperStub = new Mock <IMapper>(); var shoppingCartService = new ShoppingCartService(unitOfWorkMock.Object, mapperStub.Object); var author1 = new Author { Id = 1, AuthorName = "Author1" }; var books = new List <Book> { new Book { Id = 1, Isbn = "123", Title = "C# Unleashed", Author = author1, CategoryId = 1, Price = 10 }, new Book { Id = 2, Isbn = "213", Title = "ASP.Net Unleashed", Author = author1, CategoryId = 1, Price = 10 }, new Book { Id = 3, Isbn = "312", Title = "Java Unleashed", Author = author1, CategoryId = 1, Price = 10 } }; var user1 = new BookstoreUser() { FirstName = "Pesho", LastName = "Petrov", Id = 2, Email = "email", PhoneNumber = "0888888", }; var shoppingCartStatus = new ShoppingCartStatus() { Id = 1, ShoppingCartStatusDescription = "test" }; var shoppingCart = new ShoppingCart() { Books = books, Id = 1, UserId = 2, ShoppingCartStatus = shoppingCartStatus, ShoppingCartStatusId = shoppingCartStatus.Id }; var shoppingCarts = new List <ShoppingCart>() { shoppingCart }.AsQueryable(); unitOfWorkMock.Setup(x => x.Users.GetById(2)).Returns(user1); unitOfWorkMock.Setup(x => x.ShoppingCarts.All()).Returns(shoppingCarts); var expectedTotalPrice = 30; var actualTotalPrice = shoppingCartService.GetCartTotalPrice(user1.Id); Assert.AreEqual(expectedTotalPrice, actualTotalPrice); }
public String ConvertFrom(ShoppingCartStatus value) { return(value.ToString()); }
public void Apply(ShoppingCartCancelled @event) { ShoppingCartStatus = ShoppingCartStatus.Cancelled; }
public void Apply(ShoppingCartOrdered @event) { ShoppingCartStatus = ShoppingCartStatus.Ordered; }