public ActionResult Get_Consumables(ConsumableViewModel cViewModel) { try { if ((cViewModel.Filter.Category_Id > 0) && !string.IsNullOrEmpty(cViewModel.Filter.Material_Name)) { cViewModel.Consumables = _consumableMan.Get_Consumable_By_Category_Id_By_Material_Name(cViewModel.Filter.Category_Id, cViewModel.Filter.Material_Name, cViewModel.Pager); } else if (cViewModel.Filter.Category_Id > 0) { cViewModel.Consumables = _consumableMan.Get_Consumable_By_Category_Id(cViewModel.Filter.Category_Id, cViewModel.Pager); } else if (!string.IsNullOrEmpty(cViewModel.Filter.Material_Name)) { cViewModel.Consumables = _consumableMan.Get_Consumable_By_Material_Name(cViewModel.Filter.Material_Name, cViewModel.Pager); } else { cViewModel.Consumables = _consumableMan.Get_Consumables(cViewModel.Pager); } cViewModel.Pager.PageHtmlString = PageHelper.NumericPager("javascript:PageMore({0})", cViewModel.Pager.TotalRecords, cViewModel.Pager.CurrentPage + 1, cViewModel.Pager.PageSize, 10, true); } catch (Exception ex) { cViewModel.Friendly_Message.Add(MessageStore.Get("SYS01")); } return(Json(cViewModel, JsonRequestBehavior.AllowGet)); }
private void SaveConsumableUpdate(ConsumableViewModel x) { EditingConsumable = null; EditingServingsConsumable = null; // new food item if (x.Id == null) { var newModel = new ConsumableViewModel(); newModel.Clone(x); newModel.Id = Guid.NewGuid().ToString(); Consumables.Add(newModel); } else { // Update existing food item var food = Consumables.FirstOrDefault(y => y.Id == x.Id); if (food == null) { var newModel = new ConsumableViewModel(); newModel.Clone(x); Consumables.Add(newModel); } else { food.Clone(x); // We save when we change the collection, so this is the only place we need to call save SaveConsumables(); } } }
public ActionResult AddConsumable(ConsumableViewModel model) { if (!ModelState.IsValid) { return(PartialView("_ConsumableForm", model)); } var consumable = this.consumableService.AddConsumable(model.PlaceId, model.Name, model.Quantity, model.Price, model.Type, model.Ingredients); return(PartialView("_Consumable", model)); }
public void AddConsumableShould_CallConsumableServiceMethodAddConsumable_WhenModelIsValid() { var consumableServiceMock = new Mock <IConsumableService>(); var placeServiceMock = new Mock <IPlaceService>(); var facctoryMock = new Mock <IViewModelFactory>(); var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object, placeServiceMock.Object, facctoryMock.Object); var model = new ConsumableViewModel(); controller.AddConsumable(model); consumableServiceMock.Verify(s => s.AddConsumable(model.PlaceId, model.Name, model.Quantity, model.Price, model.Type, model.Ingredients)); }
public ActionResult Update(ConsumableViewModel cViewModel) { try { _consumableMan.Update_Consumable(cViewModel.Consumable); cViewModel.Friendly_Message.Add(MessageStore.Get("CU013")); } catch (Exception ex) { cViewModel.Friendly_Message.Add(MessageStore.Get("SYS01")); } return(Json(cViewModel)); }
public void AddConsumableShould_ReturnViewWithCorrectModel_WhenModelIssValid() { var consumableServiceMock = new Mock <IConsumableService>(); var placeServiceMock = new Mock <IPlaceService>(); var facctoryMock = new Mock <IViewModelFactory>(); var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object, placeServiceMock.Object, facctoryMock.Object); var model = new ConsumableViewModel(); controller .WithCallTo(c => c.AddConsumable(model)) .ShouldRenderPartialView("_Consumable") .WithModel(model); }
public ActionResult Search(ConsumableViewModel cViewModel) { ViewBag.Title = "KPCL ERP :: Search"; try { cViewModel.Categories = _consumableMan.Get_Category_Name(cViewModel.Pager); } catch (Exception ex) { cViewModel.Friendly_Message.Add(MessageStore.Get("SYS01")); Logger.Error(" Consumable Controller - Index " + ex.ToString()); } return(View("Search", cViewModel)); }
public ActionResult Get_Consumable_By_Id(ConsumableViewModel cViewModel) { try { cViewModel.Consumable = _consumableMan.Get_Consumable_By_Id(cViewModel.Consumable.Consumable_Id); cViewModel.Categories = _consumableMan.Get_Category_Name(cViewModel.Pager); cViewModel.SubCategories = _consumableMan.Get_SubCategory_Name(cViewModel.Pager); cViewModel.Consumable.Consumable_Vendors = _consumableMan.Get_Consumable_Vendor_By_Consumable_Id(Convert.ToInt32(cViewModel.Consumable.Consumable_Id)); } catch (Exception ex) { throw ex; } return(View("Index", cViewModel)); }
public JsonResult Insert(ConsumableViewModel cViewModel) { try { int consumableId = _consumableMan.Insert_Consumable(cViewModel.Consumable); cViewModel.Consumable.Consumable_Id = consumableId; cViewModel.Friendly_Message.Add(MessageStore.Get("C011")); } catch (Exception ex) { cViewModel.Friendly_Message.Add(MessageStore.Get("SYS01")); } return(Json(cViewModel, JsonRequestBehavior.AllowGet)); }
public JsonResult Update_Consumable_Vendors(ConsumableViewModel cViewModel) { try { _consumableMan.Update_Consumable_Vendors(cViewModel.Consumable); cViewModel.Consumable.Consumable_Vendors = _consumableMan.Get_Consumable_Vendor_By_Consumable_Id(cViewModel.Consumable.Consumable_Id); cViewModel.Friendly_Message.Add(MessageStore.Get("CV014")); } catch (Exception ex) { cViewModel.Friendly_Message.Add(MessageStore.Get("SYS01")); } return(Json(cViewModel)); }
public void AddConsumableShould_ReturnSameView_WhenModelIsNotValid() { var consumableServiceMock = new Mock <IConsumableService>(); var placeServiceMock = new Mock <IPlaceService>(); var facctoryMock = new Mock <IViewModelFactory>(); var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object, placeServiceMock.Object, facctoryMock.Object); var model = new ConsumableViewModel(); controller.ModelState.AddModelError("key", "message"); controller .WithCallTo(c => c.AddConsumable(model)) .ShouldRenderPartialView("_ConsumableForm") .WithModel(model); }
public ActionResult Insert_Consumable_Vendor(ConsumableViewModel cViewModel) { try { cViewModel.Consumable.Consumable_Vendor.Consumable_Vendor_Id = _consumableMan.Insert_Consumable_Vendor(cViewModel.Consumable); cViewModel.Friendly_Message.Add(MessageStore.Get("CV011")); //cViewModel.Consumable.Consumable_Vendors = _consumableMan.Get_Consumable_Vendor_By_Consumable_Id(Convert.ToInt32(cViewModel.Consumable.Consumable_Id)); cViewModel.Consumable.Consumable_Vendors = _consumableMan.Get_Consumable_Vendor_By_Consumable_Id(cViewModel.Consumable.Consumable_Id); } catch (Exception ex) { cViewModel.Friendly_Message.Add(MessageStore.Get("SYS01")); } return(Json(cViewModel, JsonRequestBehavior.AllowGet)); }
public void GetNewFormShould_ReturnViewWithCorrectModel_WhenPassedIdIsNotNull() { var consumableServiceMock = new Mock <IConsumableService>(); var placeServiceMock = new Mock <IPlaceService>(); var factoryMock = new Mock <IViewModelFactory>(); var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object, placeServiceMock.Object, factoryMock.Object); var id = Guid.NewGuid(); var model = new ConsumableViewModel() { PlaceId = id }; factoryMock.Setup(f => f.CreateConsumableViewModel(id)).Returns(model); controller .WithCallTo(c => c.GetNewForm(id)) .ShouldRenderPartialView("_ConsumableForm") .WithModel(model); }
public EditConsumableViewModel(ConsumableViewModel editing, Action <ConsumableViewModel> saveCallback) : base() { _saveCallback = saveCallback; if (editing != null) { Clone(editing); } else { // Default values Unit = "g"; } this.PropertyChanged += (sender, args) => { if (args.PropertyName != nameof(CanSave)) { OnPropertyChanged(nameof(CanSave)); } }; }
public ConsumableView() { InitializeComponent(); BindingContext = new ConsumableViewModel(); }