Esempio n. 1
0
        public ActionResult CreateStore(StoreViewModel vm)
        {
            ViewBag.ParentCostCentreList = _storeViewModelBuilder.ParentCostCentre();
            ViewBag.CostCentreTypeList = _storeViewModelBuilder.CostCentreTypes();

            try
            {
                vm.Id = Guid.NewGuid();
                _storeViewModelBuilder.Save(vm);

                TempData["msg"] = "Store Successfully Created";

                return RedirectToAction("ListStores");
            }
            catch (DomainValidationException ve)
            {
                ValidationSummary.DomainValidationErrors(ve, ModelState);
                _log.Debug("Failed to create stores " + ve.Message);
                _log.Error("Failed to create stores" + ve.ToString());

                return View(vm);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                _log.Debug("Failed to create stores " + ex.Message);
                _log.Error("Failed to create stores" + ex.ToString());

                return View(vm);
            }

        }
 StoreViewModel Map(Store store)
 {
     StoreViewModel storeViewModel = new StoreViewModel();
     storeViewModel.Id = store.Id;
     storeViewModel.Code = store.CostCentreCode;
     storeViewModel.Name = store.Name;
     storeViewModel.VatRegistrationNo = store.VatRegistrationNo;
     storeViewModel.Longitude = store.Longitude;
     storeViewModel.Latitude = store.Latitude;
     storeViewModel.ParentCostCentreId = store.ParentCostCentre.Id;
     storeViewModel.ParentCostCentreName = _hubRepository.GetById(store.ParentCostCentre.Id).Name;
     storeViewModel.IsActive = (int)store._Status;
     return storeViewModel;
 }
 public void Save(StoreViewModel storeViewModel)
 {
     Guid Id = Guid.NewGuid();
     if(storeViewModel.Id != null)
     {
         Id = storeViewModel.Id;
     }
     Store store = new Store(Id);
     store.Name = storeViewModel.Name;
     store.CostCentreCode = storeViewModel.Code;
     store.VatRegistrationNo = storeViewModel.VatRegistrationNo;
     store.Longitude = storeViewModel.Longitude;
     store.Latitude = storeViewModel.Latitude;
     store._Status = EntityStatus.Active;
     store.ParentCostCentre = new CostCentreRef { Id = storeViewModel.ParentCostCentreId };// _producerRepository.GetById();
     store.CostCentreType = CostCentreType.Store;
     _storeRepository.Save(store);
 }