public bool DeleteCommodity(Commodity commodity) { if (commodity == null) return false; _unitOfWork.CommodityRepository.Delete(commodity); _unitOfWork.Save(); return true; }
public static Commodity BindCommodity(CommodityViewModel commodityViewModel, Commodity commodity = null) { return new Commodity() { CommodityID = commodityViewModel.CommodityID, Name = commodityViewModel.Name, CommodityCode = commodityViewModel.CommodityCode, NameAM = commodityViewModel.NameAM, LongName = commodityViewModel.LongName, CommodityTypeID = commodityViewModel.CommodityTypeID, ParentID = commodityViewModel.ParentID }; }
public static CommodityViewModel BindCommodityViewModel(Commodity commodity) { return new CommodityViewModel() { CommodityID = commodity.CommodityID, Name = commodity.Name, CommodityCode = commodity.CommodityCode, NameAM = commodity.NameAM, LongName = commodity.LongName, CommodityTypeID = commodity.CommodityTypeID, ParentID = commodity.CommodityTypeID }; }
public static CommodityViewModel BindCommodityViewModel(Commodity commodity) { if (commodity.ParentID != null) return new CommodityViewModel() { CommodityID = commodity.CommodityID, Name = commodity.Name, CommodityCode = commodity.CommodityCode, NameAM = commodity.NameAM, LongName = commodity.LongName, CommodityTypeID = commodity.CommodityTypeID, ParentID = (int) commodity.ParentID }; return null; }
public void CanDoCreatePostback() { //ACT var commodity = new Commodity{Name = "Rice", CommodityCode = null, CommodityTypeID = 1, ParentID = 1, CommodityID = 1}; var result = _commodityController.Create(commodity); Assert.IsNotNull(result); var viewResult = result as ViewResult; var model = viewResult.Model; var jsonResult = result as JsonResult; //ASSERT Assert.IsNotNull(jsonResult); dynamic data = jsonResult.Data; Assert.AreEqual(true, data.success); Assert.IsInstanceOf<Commodity>(model); }
public bool EditCommodity(Commodity commodity) { _unitOfWork.CommodityRepository.Edit(commodity); _unitOfWork.Save(); return true; }
public bool AddCommodity(Commodity commodity) { _unitOfWork.CommodityRepository.Add(commodity); _unitOfWork.Save(); return true; }
public IEnumerable<BinCardViewModel> GetBinCard(int hubID, int? StoreID, int? CommodityID, string ProjectID) { var commodity = new Commodity(); if (CommodityID.HasValue) commodity = FindCommodityById(CommodityID.Value); List<BinCardReport> results = new List<BinCardReport>(); //TODO:the logic should be verified(Robi) if (commodity != null && commodity.CommodityTypeID == 1) results = _unitOfWork.ReportRepository.RPT_BinCard(hubID, StoreID, CommodityID, ProjectID).ToList(); else results = _unitOfWork.ReportRepository.RPT_BinCard(hubID, StoreID, CommodityID, ProjectID).ToList(); //var results = db.RPT_BinCard(hubID,StoreID,CommodityID,ProjectID); var returnValue = new List<BinCardViewModel>(); decimal balance = 0; foreach (var res in results) { balance += (res.Received.HasValue) ? res.Received.Value : 0; balance -= (res.Dispatched.HasValue) ? res.Dispatched.Value : 0; returnValue.Add(new BinCardViewModel { SINumber = res.SINumber, DriverName = res.DriverName, Transporter = res.Transporter, TransporterAM = res.TransporterAM, Date = res.Date, Project = res.Project, Dispatched = res.Dispatched, Received = res.Received, Balance = balance, Identification = res.Identification, ToFrom = res.ToFrom }); } return returnValue; }
public void CanDoEditPostBack() { //ACT var commodity = new Commodity {CommodityID = 1, Name = "Cereal", CommodityCode = "CER", CommodityTypeID = 1, ParentID = null}; var result = _commodityController.Edit(commodity); var jsonResult = result as JsonResult; //ASSERT Assert.IsNotNull(jsonResult); dynamic data = jsonResult.Data; Assert.AreEqual(true, data.success); }
public ActionResult Edit(Commodity commodity) { // TODO: move this to a shared helper function. if (!_commodityService.IsCodeValid(commodity.CommodityID, commodity.CommodityCode)) { ModelState.AddModelError("CommodityCode", @"Commodity Code should be unique."); } if (!_commodityService.IsNameValid(commodity.CommodityID, commodity.Name)) { ModelState.AddModelError("Name", @"Commodity Name should be unique."); } if (ModelState.IsValid) { _commodityService.EditCommodity(commodity); return Json(new { success = true }); } Edit(commodity.CommodityID); return PartialView(commodity); }
public ActionResult Create(Commodity commodity) { if(!_commodityService.IsCodeValid(commodity.CommodityID,commodity.CommodityCode)) { ModelState.AddModelError("CommodityCode",@"Commodity Code should be unique."); } if (!_commodityService.IsNameValid(commodity.CommodityID, commodity.Name)) { ModelState.AddModelError("Name", @"Commodity Name should be unique."); } if (ModelState.IsValid) { _commodityService.AddCommodity(commodity); return Json(new { success = true }); } Create(commodity.ParentID != null ? 0 : 1, commodity.ParentID); return PartialView(commodity); }
/** * <type> indicates the type of commodity to be (parent/child)</type> * <Parent> An Optional Nullable value param for preseting the sub Commoditites to be created</Praent> */ // // GET: /Commodity/Create public ActionResult Create(int type, int? parent) { //TODO validation check @ the post server side if the user mischively sent a non-null parent //this check should also be done for the editing part if (0 == type) { ViewBag.ParentID = new SelectList(_commodityService.GetAllParents(), "CommodityID", "Name", parent); //drop down boxes don't remove thses cos i used them to set a hidden value var firstOrDefault = _commodityService.GetAllParents().FirstOrDefault(p => p.CommodityID == parent); if (firstOrDefault != null){ ViewBag.CommodityTypeID = new SelectList(_commodityTypeService.GetAllCommodityType(), "CommodityTypeID", "Name", firstOrDefault.CommodityTypeID); } else { //TODO null value validation can be set here later ViewBag.CommodityTypeID = new SelectList(_commodityTypeService.GetAllCommodityType(), "CommodityTypeID", "Name"); } //disabled text boxes (elias worte this part i think) ViewBag.isParent = true; if (parent != null) { var commodity = _commodityService.FindById(parent.Value); if (commodity.CommodityType != null){ ViewBag.CommodityType = commodity.CommodityType.Name; ViewBag.ParentCommodity = commodity.Name; ViewBag.SelectedCommodityID = commodity.CommodityID; } else { ViewBag.CommodityType = ""; ViewBag.ParentCommodity = ""; } } } else { ViewBag.CommodityTypeID = new SelectList(_commodityService.GetAllCommodity(), "CommodityTypeID", "Name"); ViewBag.isParent = false; } var partialCommodity = new Commodity(); var partialParent = _commodityService.GetAllParents().FirstOrDefault(p => p.CommodityID == parent); if (partialParent != null) { partialCommodity.CommodityTypeID = partialParent.CommodityTypeID; } //TODO either ways it will be null, but we can make this assignment to null/and move it in side else after testing //to be sure for preventing hierarchy(tree) partialCommodity.ParentID = parent; return PartialView(partialCommodity); }