Exemplo n.º 1
0
func (controller *HomeController) Edit(input *HomeEditInput) mvc.ActionResultInterface {
	product := controller.findProduct(input.ProductId)
	if product == nil {
		product = new(Product)
	}

	return mvc.JsonResult(ProductVMFromProduct(product))
}
Exemplo n.º 2
0
func (controller *HomeController) EditPost(productVM *ProductVM) mvc.ActionResultInterface {
	if len(productVM.Name) == 0 {
		productVM.Error = "Name can't be empty"
		return mvc.JsonResult(productVM)
	}

	productToUpdate := controller.findProduct(productVM.ProductId)
	if productToUpdate == nil {
		productAddSync.Lock()
		defer productAddSync.Unlock()

		productToUpdate = &Product{len(products) + 1, "", ""}
		products = append(products, productToUpdate)
	}

	productToUpdate.Name = productVM.Name
	productToUpdate.Description = productVM.Description

	return mvc.JsonResult(ProductVMFromProduct(productToUpdate))
}
Exemplo n.º 3
0
func (controller *HomeController) List() mvc.ActionResultInterface {
	return mvc.JsonResult(products)
}