示例#1
0
 public bool AddOrUpdate(CustomerModel model)
 {
     if (model.Id > 0)
     {
         var entity = _customerRepository.Table.FirstOrDefault(x => x.Id == model.Id);
         entity.Name       = model.Name;
         entity.ModifyTime = DateTime.Now;
         entity.Active     = model.Active;
         return(_customerRepository.Update(entity) > 0);
     }
     else
     {
         var entity = new Customer
         {
             Name        = model.Name,
             Email       = model.Email,
             CreatedTime = DateTime.Now,
             Active      = model.Active,
             Type        = model.Type,
             ParentId    = model.ParentId,
             PassWord    = SignUtil.MD5Sign(model.PassWord)
         };
         return(_customerRepository.Insert(entity) > 0);
     }
 }
示例#2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                ErrorNotification("验证码错误");
                return(View());
            }
            var passWod  = SignUtil.MD5Sign(model.PassWord);
            var customer = _customerService.GetCustomer(model.Email, passWod);

            if (customer == null)
            {
                ErrorNotification("用户名或密码错误");
            }
            else
            {
                _workContext.CurrentCustomer = customer;
                if (!string.IsNullOrEmpty(returnUrl))
                {
                    return(Redirect(returnUrl));
                }

                return(RedirectToAction("Index", "Home"));
            }
            return(View());
        }
示例#3
0
        protected override void Seed(FrameDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //


            context.Set <Customer>().AddOrUpdate(
                p => p.Type,
                new Customer
            {
                Name        = "Admin",
                Email       = "*****@*****.**",
                PassWord    = SignUtil.MD5Sign("888888"),
                Active      = true,
                Type        = CustomerTypeEnum.SuperAdmin,
                CreatedTime = DateTime.Now,
                ParentId    = 0,
                Roles       = new List <Role>
                {
                    new Role
                    {
                        Name        = "³¬¼¶¹ÜÀíÔ±",
                        Active      = true,
                        ParentId    = 0,
                        Type        = RoleTypeEnum.SuperAdminRole,
                        CreatedTime = DateTime.Now,
                        SystemName  = "Admin_SuperRole"
                    }
                }
            }
                );
        }