Example #1
0
 public ActiveTypeModel(Data.Entities.ActiveType source)
 {
     Id       = source.Id;
     TypeCode = source.TypeCode;
     TypeName = source.TypeName;
     BaseAmmortizationMounth = source.BaseAmmortizationMounth;
 }
        public ActionResult CreateActiveType(ActiveTypeModel newActiveType)
        {
            if (newActiveType.BaseAmmortizationMounth.HasValue && newActiveType.BaseAmmortizationMounth.Value < 0)
            {
                ModelState.AddModelError("BaseAmmortizationMounth", "Неверно указан срок амортизации");
            }

            if (ModelState.IsValid)
            {
                var newActive = new Data.Entities.ActiveType
                {
                    TypeCode = newActiveType.TypeCode,
                    TypeName = newActiveType.TypeName,
                    BaseAmmortizationMounth = newActiveType.BaseAmmortizationMounth
                };
                var validate = catalogsValidator.ValidateActiveTypeBeforeSave(newActive);

                if (validate.IsValid)
                {
                    activeTypesService.SaveActiveType(newActive);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.WarningMessage = validate.ValidationMessage;
                }
            }
            return(View(newActiveType));
        }
        public ActiveTypeDetailsViewModel(Data.Entities.ActiveType source)
        {
            Id       = source.Id;
            TypeCode = source.TypeCode;
            TypeName = source.TypeName;
            BaseAmmortizationMounth = source.BaseAmmortizationMounth;

            ActiveSpecifications = new List <ActiveSpecificationTypeModel>();
            if (source.ActiveSpecifications != null)
            {
                foreach (var item in source.ActiveSpecifications)
                {
                    ActiveSpecifications.Add(new ActiveSpecificationTypeModel(item));
                }
            }
        }