コード例 #1
0
        // GET: Elements/Edit/5
        public ActionResult Edit(int id)
        {
            var viewModel    = service.GetElement(id);
            var bindingModel = new ElementBindingModel
            {
                Id          = id,
                ElementName = viewModel.ElementName
            };

            return(View(bindingModel));
        }
コード例 #2
0
        public void AddElement(ElementBindingModel model)
        {
            int maxId = 0;

            for (int i = 0; i < source.Elements.Count; ++i)
            {
                if (source.Elements[i].Id > maxId)
                {
                    maxId = source.Elements[i].Id;
                }
                if (source.Elements[i].ElementName == model.ElementName)
                {
                    throw new Exception("Уже есть компонент с таким названием");
                }
            }
            source.Elements.Add(new Element
            {
                Id          = maxId + 1,
                ElementName = model.ElementName
            });
        }
コード例 #3
0
        public void UpdElement(ElementBindingModel model)
        {
            int index = -1;

            for (int i = 0; i < source.Elements.Count; ++i)
            {
                if (source.Elements[i].Id == model.Id)
                {
                    index = i;
                }
                if (source.Elements[i].ElementName == model.ElementName &&
                    source.Elements[i].Id != model.Id)
                {
                    throw new Exception("Уже есть компонент с таким названием");
                }
            }
            if (index == -1)
            {
                throw new Exception("Элемент не найден");
            }
            source.Elements[index].ElementName = model.ElementName;
        }