Esempio n. 1
0
        public void SaveParty(Party party, IActionBy actionBy)
        {
            if(this.GetPartyByGuid(party.Guid) == null)
            {
                string sql = @"Insert Into VintageRabbit.Parties (Guid, OrderGuid, Status, PartyDate, DropoffAddress, PickupAddress, ChildsName, Age, PartyTime, [PartyAddress], [RSVPDetails], DateCreated, DateLastModified, LastModifiedBy)
                                Values (@Guid, @OrderGuid, @Status, @PartyDate, @DropoffAddress, @PickupAddress, @ChildsName, @Age, @PartyTime, @PartyAddress, @RSVPDetails, @DateCreated, @DateLastModified, @LastModifiedBy)";

                using (SqlConnection connection = new SqlConnection(this._connectionString))
                {
                    connection.Execute(sql, new
                    {
                        Guid = party.Guid,
                        OrderGuid = party.OrderGuid,
                        Status = party.Status.ToString(),
                        PartyDate = party.PartyDate,
                        DropoffAddress = party.DropoffAddress,
                        PickupAddress = party.PickupAddress,
                        ChildsName = party.ChildsName,
                        Age = party.Age,
                        PartyTime = party.PartyTime,
                        PartyAddress = party.PartyAddress,
                        RSVPDetails = party.RSVPDetails,
                        DateCreated = DateTime.Now,
                        DateLastModified = DateTime.Now,
                        LastModifiedBy = actionBy.Email
                    });
                }
            }
            else
            {
                string sql = @"Update VintageRabbit.Parties Set OrderGuid = @OrderGuid, Status = @Status, PartyDate = @PartyDate, DropoffAddress = @DropoffAddress,
                                PickupAddress = @PickupAddress, ChildsName = @ChildsName, Age = @Age, PartyTime = @PartyTime, [PartyAddress] = @PartyAddress, RSVPDetails = @RSVPDetails,
                                DateLastModified = @DateLastModified, LastModifiedBy = @LastModifiedBy Where Guid = @Guid";

                using (SqlConnection connection = new SqlConnection(this._connectionString))
                {
                    connection.Execute(sql, new
                    {
                        Guid = party.Guid,
                        OrderGuid = party.OrderGuid,
                        Status = party.Status.ToString(),
                        PartyDate = party.PartyDate,
                        DropoffAddress = party.DropoffAddress,
                        PickupAddress = party.PickupAddress,
                        ChildsName = party.ChildsName,
                        Age = party.Age,
                        PartyTime = party.PartyTime,
                        PartyAddress = party.PartyAddress,
                        RSVPDetails = party.RSVPDetails,
                        DateLastModified = DateTime.Now,
                        LastModifiedBy = actionBy.Email
                    });
                }
            }
        }
        public Product SaveProduct(Product product, IActionBy actionBy)
        {
            string categories = this._serializer.Serialize(product.Categories);
            string images = this._serializer.Serialize(product.Images);

            if (product.Id == 0)
            {
                string sql = @"Insert Into VintageRabbit.Products
                                ([Guid], Code, [Type], Title, Description, Price, Keywords, Inventory, IsFeatured, DateCreated, DateLastModified, UpdatedBy, Categories, Images)
                                Values
                                (@Guid, @Code, @Type, @Title, @Description, @Price, @Keywords, @Inventory, @IsFeatured, @DateCreated, @DateLastModified, @UpdatedBy, @Categories, @Images);
                                Select cast(SCOPE_IDENTITY() as int)";

                using (SqlConnection connection = new SqlConnection(this._connectionString))
                {
                    IEnumerable<int> productIds = connection.Query<int>(sql, new
                    {
                        Guid = product.Guid,
                        Code = product.Code,
                        Type = product.Type.ToString(),
                        Title = product.Title,
                        Description = product.Description,
                        Price = product.Cost,
                        Keywords = product.Keywords,
                        IsFeatured = product.IsFeatured,
                        DateCreated = DateTime.Now,
                        DateLastModified = DateTime.Now,
                        UpdatedBy = actionBy.Email,
                        Categories = categories,
                        Inventory = product.Inventory,
                        Images = images
                    });

                    if(productIds.Any())
                    {
                        product.Id = productIds.First();
                    }
                }
            }
            else
            {
                string sql = @"Update VintageRabbit.Products Set [Guid] = @Guid, Code = @Code, [Type] = @Type, Title = @Title, Description = @Description, Price = @Price, Keywords = @Keywords,
                                IsFeatured = @IsFeatured, Inventory = @Inventory, DateLastModified = @DateLastModified, UpdatedBy = @UpdatedBy, Categories = @Categories, Images = @Images
                                Where Id = @ProductId";

                using (SqlConnection connection = new SqlConnection(this._connectionString))
                {
                    connection.Execute(sql, new
                    {
                        Guid = product.Guid,
                        Code = product.Code,
                        Type = product.Type.ToString(),
                        Title = product.Title.Trim(),
                        Description = product.Description.Trim(),
                        Price = product.Cost,
                        Keywords = product.Keywords,
                        IsFeatured = product.IsFeatured,
                        DateLastModified = DateTime.Now,
                        UpdatedBy = actionBy.Email,
                        Categories = categories,
                        Inventory = product.Inventory,
                        Images = images,
                        ProductId = product.Id
                    });
                }
            }

            this.SaveProductCategories(product);

            return product;
        }
 public SaveProductMessage(Product product, IActionBy actionBy)
 {
     this.Product = product;
     this.ActionBy = actionBy;
 }