Beispiel #1
0
        public IActionResult Create(CreateGroupViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Items = PopulateIndestries();
                return(View(model));
            }

            if (model.IndustryId == "-1")
            {
                ModelState.AddModelError(string.Empty, "必须选择行业");
            }

            if (IsGroupNameExists(model.GroupName) == false)
            {
                ModelState.AddModelError(string.Empty, "集团名称已经存在");
            }

            if (ModelState.ErrorCount > 0)
            {
                model.Items = PopulateIndestries();
                return(View(model));
            }

            var dbGroup = new DD.Electricity.Cloud.Domain.Entities.Headquarter.Group();

            dbGroup.Name       = model.GroupName;
            dbGroup.IndustryId = int.Parse(model.IndustryId);

            _hdDbContext.Groups.Add(dbGroup);
            _hdDbContext.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #2
0
        public IActionResult Create(CreateProjectViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Items = PopulateGroup();
                return(View(model));
            }
            if (IsProjectNameExists(model.ProjectName) == false)
            {
                ModelState.AddModelError(string.Empty, "项目的名称已经存在");
            }
            if (ModelState.ErrorCount > 0)
            {
                model.Items = PopulateGroup();
                return(View(model));
            }
            var dbProject = new DD.Electricity.Cloud.Domain.Entities.Headquarter.Project();

            dbProject.Name    = model.ProjectName;
            dbProject.GroupId = int.Parse(model.GroupId);

            _hdDbContext.Projects.Add(dbProject);
            _hdDbContext.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
 public IActionResult Edit(int id, UserEditViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var users = _hdDbContext.RegisteQueries.FirstOrDefault(t => t.Id == id);
             users.Name = model.Name;
             _hdDbContext.RegisteQueries.Update(users);
             _hdDbContext.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(RedirectToAction("Index"));
 }