示例#1
0
        public IActionResult New(string objectName, IFormCollection form)
        {
            ModelState.Clear();
            var domainType = Typer.GetTyper(objectName);

            var vmType = Typer.GetRefTyper("ViewModel", domainType, TyperAction.Insert);

            if (vmType == null)
            {
                return(NotFound());
            }

            var model = BindModel(form, vmType);

            var viewName = $"{objectName}New";

            if (!TryValidateModel(model))
            {
                return(View(viewName, model));
            }

            var entity = Mapper.Map(model, model.GetType(), domainType) as IDefaultEntity;

            service.Add(entity);
            uoW.SaveChanges();

            return(RedirectToAction("List", new { objectName }));
        }
示例#2
0
        public IActionResult Edit(string objectName, Guid id, IFormCollection form)
        {
            ModelState.Clear();
            var domainType = Typer.GetTyper(objectName);

            var vmType = Typer.GetRefTyper("ViewModel", domainType, TyperAction.Update);

            if (vmType == null)
            {
                return(NotFound());
            }

            var model = BindModel(form, vmType);

            if (!TryValidateModel(model))
            {
                var viewName = $"{objectName}/Edit";
                return(View(viewName, model));
            }

            var entity = repositoryRead.GetSingle(objectName, id) as IDefaultEntity;

            Mapper.Map(model, entity, vmType, domainType);
            service.Update(entity);
            uoW.SaveChanges();

            return(RedirectToAction("List", new { objectName }));
        }
示例#3
0
        public IActionResult Delete(string objectName, Guid id)
        {
            ModelState.Clear();

            var type = Typer.GetTyper(objectName);

            service.Delete(type, id);
            uoW.SaveChanges();
            return(ResponseApi(id));
        }