コード例 #1
0
        public bool AddDemand(DemandViewModelEdit demandViewModelEdit, out string reason)
        {
            reason = string.Empty;
            var demand = _demandDbContext.Demands.SingleOrDefault(item => item.DemandCode == demandViewModelEdit.DemandCode);

            if (demand != null)
            {
                reason = "已存在名称:" + demandViewModelEdit.DemandCode;
                return(false);
            }
            Demand newDemand = new Demand();

            newDemand.Id           = 0;
            newDemand.DemandCode   = demandViewModelEdit.DemandCode;
            newDemand.DemandType   = (DemandType)demandViewModelEdit.DemandType;
            newDemand.DemandDetail = demandViewModelEdit.DemandDetail;
            newDemand.UserId       = demandViewModelEdit.UserId;
            newDemand.CustomerId   = demandViewModelEdit.CustomerId;
            newDemand.Remarks      = demandViewModelEdit.Remarks;

            newDemand.DemandPhase       = DemandPhase.需求提出;
            newDemand.CreateTime        = DateTime.Now;
            newDemand.SoftwareVersionId = null;
            _demandDbContext.Demands.Add(newDemand);
            _demandDbContext.SaveChanges();
            return(true);
        }
コード例 #2
0
        public bool AddRole(RoleViewModel roleViewModel, out string reason)
        {
            reason = string.Empty;
            var newRole = AutoMapper.Mapper.Map <Role>(roleViewModel);
            var role    = _demandDbContext.Roles.FirstOrDefault(item => item.Name == newRole.Name);

            if (role != null)
            {
                reason = "已存在名称:" + newRole.Name;
                return(false);
            }
            newRole.CreateTime = DateTime.Now;
            _demandDbContext.Roles.Add(newRole);
            _demandDbContext.SaveChanges();
            return(true);
        }
コード例 #3
0
        public bool AddSoftwareVersion(SoftwareVersionViewModel softwareVersionViewModel, out string reason)
        {
            reason = string.Empty;
            var newSoftwareVersion = AutoMapper.Mapper.Map <SoftwareVersion>(softwareVersionViewModel);
            var softwareVersion    = _demandDbContext.SoftwareVersions.SingleOrDefault(item => item.VersionName == newSoftwareVersion.VersionName);

            if (softwareVersion != null)
            {
                reason = "已存在名称:" + newSoftwareVersion.VersionName;
                return(false);
            }
            newSoftwareVersion.IsDeleted = 0;
            _demandDbContext.SoftwareVersions.Add(newSoftwareVersion);
            _demandDbContext.SaveChanges();
            return(true);
        }
コード例 #4
0
        public bool AddCustomer(CustomerViewModel customerViewModel, out string reason)
        {
            reason = string.Empty;
            var newCustomer = AutoMapper.Mapper.Map <Customer>(customerViewModel);
            var customer    = _demandDbContext.Customers.SingleOrDefault(item => item.Name == newCustomer.Name);

            if (customer != null)
            {
                reason = "已存在名称:" + newCustomer.Name;
                return(false);
            }
            newCustomer.CreateTime    = DateTime.Now;
            newCustomer.CustomerState = CustomerState.正常;
            _demandDbContext.Customers.Add(newCustomer);
            _demandDbContext.SaveChanges();
            return(true);
        }
コード例 #5
0
        public bool AddUser(UserViewModel userViewModel, out string reason)
        {
            reason = string.Empty;
            var newUser = AutoMapper.Mapper.Map <User>(userViewModel);
            var user    = _demandDbContext.Users.FirstOrDefault(item => item.UserName == newUser.UserName);

            if (user != null)
            {
                reason = "已存在名称:" + newUser.UserName;
                return(false);
            }
            newUser.Password   = "******";
            newUser.CreateTime = DateTime.Now;
            newUser.IsDeleted  = 0;
            _demandDbContext.Users.Add(newUser);
            _demandDbContext.SaveChanges();
            return(true);
        }
コード例 #6
0
        public bool AddMenu(MenuViewModel menuViewModel, out string reason)
        {
            reason = string.Empty;
            var newMenu = AutoMapper.Mapper.Map <Menu>(menuViewModel);
            var menu    = _demandDbContext.Menus.FirstOrDefault(item => item.Name == newMenu.Name);

            if (menu != null)
            {
                reason = "已存在名称:" + newMenu.Name;
                return(false);
            }
            _demandDbContext.Menus.Add(newMenu);
            //新增的功能 自动附加到管理员
            var adminRole = _demandDbContext.Roles.Single(item => item.Id == 1);

            _demandDbContext.RoleMenus.Add(new RoleMenu()
            {
                Menu = newMenu, Role = adminRole
            });
            _demandDbContext.SaveChanges();
            return(true);
        }
コード例 #7
0
 public void AddWxUser(WxUser wxUser)
 {
     _demandDbContext.WxUsers.Add(wxUser);
     _demandDbContext.SaveChanges();
 }