public ActionResult Detail_Option_Add(long product_id) { // check product exist var product = Db.Select <Product>(x => x.Where(m => m.Id == product_id).Limit(1)).FirstOrDefault(); if (product == null) { return(Redirect("/")); } var model = new OptionInProduct(); model.ProductId = product.Id; model.Product_Name = product.Name; return(View(model)); }
public ActionResult Detail_Option_Update(OptionInProduct model) { var curent_item = new OptionInProduct(); if (model.Id > 0) { curent_item = Db.Where <OptionInProduct>(m => m.Id == model.Id).FirstOrDefault(); if (curent_item == null) { return(Redirect("/")); } } else { // if we add new, make sure no dupplication var x = Db.Where <OptionInProduct>(m => m.ProductOptionId == model.ProductOptionId && m.ProductId == model.ProductId); if (x.Count > 0) { return(JsonError("Duplicated option.")); } curent_item.CreatedBy = AuthenticatedUserID; curent_item.CreatedOn = DateTime.Now; } curent_item.ProductId = model.ProductId; curent_item.ProductOptionId = model.ProductOptionId; curent_item.isRequire = model.isRequire; curent_item.DefaultQuantity = model.DefaultQuantity; curent_item.MaxQuantity = model.MaxQuantity; curent_item.MinQuantity = model.MinQuantity; curent_item.CanApplyCoupon = model.CanApplyCoupon; if (model.Id > 0) { Db.Update <OptionInProduct>(curent_item); } else { Db.Insert <OptionInProduct>(curent_item); } return(JsonSuccess(Url.Action("Detail", new { id = curent_item.ProductId }))); }