Пример #1
0
        public ActionResult AddOrEdit(int? id)
        {
            var model = new DepartmentViewModel();
            if (id.HasValue)
            {
                var item = Db.Get<Department>(id.Value);
                model = Mapper.Map(item, model);
            }

            return View(model);
        }
Пример #2
0
        public ActionResult AddOrEdit(DepartmentViewModel model)
        {
            var item = new Department();
            if (model.Id > 0)
            {
                item = Db.Get<Department>(model.Id);
            }
            item = Mapper.Map(model, item);

            var result = Db.SaveOrUpdate(item);

            return RedirectToAction("List");
        }
Пример #3
0
        private DepartmentViewModel GetDepartment(int departmentid)
        {
            var item = Db.Get<Department>(departmentid);

            var model = new DepartmentViewModel();

            Mapper.Map(item, model);

            IEnumerable<string> files = new List<string>();

            try
            {
                var directory = new DirectoryInfo(Server.MapPath(model.FilesFolder));
                files = directory.GetFiles().Select(f => f.Name);
            }
            catch (Exception ex)
            {
            }

            model.Files = files;
            return model;
        }