ContainerTypeViewModel Map(ContainerType containerType)
        {
            var vm = new ContainerTypeViewModel();
            vm.Id = containerType.Id;
            vm.Code = containerType.Code;
            vm.Name = containerType.Name;
            vm.Make = containerType.Make;
            vm.Model = containerType.Model;
            vm.Description = containerType.Description;
            vm.LoadCariage = containerType.LoadCarriage;
            vm.TareWeight = containerType.TareWeight;
            vm.Width = containerType.Width;
            vm.Height = containerType.Height;
            vm.BubbleSpace = containerType.BubbleSpace;
            vm.Volume = containerType.Volume;
            vm.FreezerTemp = containerType.FreezerTemp;
            vm.ContainerUserType = (int)containerType.ContainerUseType;
            vm.IsActive = (int)containerType._Status;

            if (containerType.CommodityGrade != null)
            {
                vm.SelectedCommodityGradeId = containerType.CommodityGrade.Id;
                vm.SelectedCommodityGradeName = containerType.CommodityGrade.Name;
                vm.SelectedCommodityId = containerType.CommodityGrade.Commodity.Id;
                vm.SelectedCommodityName = containerType.CommodityGrade.Commodity.Name;
            }
            
            return vm;
        }
        public ActionResult CreateContainerType()
        {
            ViewBag.CommodityList = _containerTypeViewModelBuilder.Commodities();
            ViewBag.ContainerTypeList = _containerTypeViewModelBuilder.ContainerUserTypes();

            var view = new ContainerTypeViewModel();
            view.CommodityList = new SelectList(_containerTypeViewModelBuilder.Commodities(), "Key", "Value");
            view.CommodityGradesList = _containerTypeViewModelBuilder.GradeByCommodity(Guid.Empty);

            return View(view);
        }
        public void Save(ContainerTypeViewModel vm)
        {
            ContainerType containerType = new ContainerType(vm.Id);
            containerType.Name = vm.Name;
            containerType.Code = vm.Code;
            containerType.Make = vm.Make;
            containerType.Model = vm.Model;
            containerType.Description = vm.Description;
            containerType.LoadCarriage = vm.LoadCariage;
            containerType.TareWeight = vm.TareWeight;
            containerType.Length = vm.Length;
            containerType.Width = vm.Width;
            containerType.Height = vm.Height;
            containerType.BubbleSpace = vm.BubbleSpace;
            containerType.Volume = vm.Volume;
            containerType.FreezerTemp = vm.FreezerTemp;
            containerType._Status = EntityStatus.Active;
            containerType.ContainerUseType = (ContainerUseType)vm.ContainerUserType;
            containerType.CommodityGrade = _commodityRepository.GetGradeByGradeId(vm.SelectedCommodityGradeId);


            _containerTypeRepository.Save(containerType);
        }
        public ActionResult CreateContainerType(ContainerTypeViewModel vm)
        {
            ViewBag.CommodityList = _containerTypeViewModelBuilder.Commodities();
            ViewBag.ContainerTypeList = _containerTypeViewModelBuilder.ContainerUserTypes();

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

                TempData["msg"] = "Container type Successfully Created";

                return RedirectToAction("ListContainerTypes");
            }
            catch (DomainValidationException ve)
            {
                ValidationSummary.DomainValidationErrors(ve, ModelState);
                Log.Debug("Failed to create Container type " + ve.Message);

                return View(vm);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                Log.Debug("Failed to create Container type " + ex.Message);

                return View(vm);
            }

        }