Example #1
0
// Note: Don't forget create an AccountChangeLog when update person's account-ballance.
func Update(person *model.Person) (affacted int64, err error) {
	if affacted, err = persondao.Update(person); err != nil {
		return
	}
	// update person
	if person.Type == "customer" {
		suggest.Update(suggest.Customer, person.Name, person.Id, "")
	} else if person.Type == "factory" {
		suggest.Update(suggest.Factory, person.Name, person.Id, "")
	}
	return
}
Example #2
0
func (s *ProductService) UpdateProduct(product *model.Product) {
	if product == nil {
		return
	}
	// update product information
	product.Capital = s.getCapital(product.Name)
	if _, err := productdao.UpdateProduct(product); err != nil {
		panic(err.Error())
	}

	// update it's properties
	if product.Colors != nil {
		productdao.UpdateProductProperties(product.Id, "color", product.Colors...)
	}
	if product.Sizes != nil {
		productdao.UpdateProductProperties(product.Id, "size", product.Sizes...)
	}

	// update stock information
	if product.Stocks != nil {
		// TODO change to edit/create/delete;
		inventorydao.ClearProductStock(product.Id) // clear
		product.Stocks.Loop(func(color, size string, stock int) {
			inventorydao.SetProductStock(product.Id, color, size, stock)
		})
	}

	// update suggest
	fmt.Println("^^^^^^ update product, ", product)
	fmt.Println("Productid is: ", product.ProductId)
	suggest.Update(suggest.Product, product.Name, product.Id, product.ProductId)

}