public static void Main()
        {
            var server = new WebServer(
                1337,
                new ControllerRouter(),
                new ResourceRouter());

            using (var db = new ChushkaContext())
            {
                if (!db.ProductTypes.Any())
                {
                    db.ProductTypes.Add(new ProductType {
                        Name = "Food"
                    });
                    db.ProductTypes.Add(new ProductType {
                        Name = "Domestic"
                    });
                    db.ProductTypes.Add(new ProductType {
                        Name = "Health"
                    });
                    db.ProductTypes.Add(new ProductType {
                        Name = "Cosmetic"
                    });
                    db.ProductTypes.Add(new ProductType {
                        Name = "Other"
                    });
                    db.SaveChanges();
                }

                db.Database.Migrate();
            }

            MvcEngine.Run(server);
        }
        public bool RegisterUser()
        {
            var userRole = Role.User;

            using (var context = new ChushkaContext())
            {
                if (!context.Users.Any())
                {
                    userRole = Role.Admin;
                }

                var result = context.Users.Add(new User()
                {
                    Username = this.Username,
                    Password = this.Password,
                    Email    = this.Email,
                    FullName = this.FullName,
                    Role     = userRole
                });

                context.SaveChanges();

                return(true);
            }
        }
示例#3
0
 public User AuthenticateUser()
 {
     using (var context = new ChushkaContext())
     {
         var userResult = from u in context.Users where u.Username == this.Username && u.Password == this.Password select u;
         return(userResult.FirstOrDefault());
     }
 }
示例#4
0
        public User RetrieveFromSession()
        {
            var userId = _session.GetInt32("userId");

            if (userId != 0)
            {
                using (var context = new ChushkaContext())
                {
                    var userResult = from u in context.Users where u.Id == userId select u;
                    return(userResult.FirstOrDefault());
                }
            }
            return(null);
        }
示例#5
0
 public UserService(ChushkaContext context, IHashService hashService)
 {
     this.context     = context;
     this.hashService = hashService;
 }
示例#6
0
 public OrderService(ChushkaContext context)
     : base(context)
 {
 }
 public UserService(ChushkaContext context)
 {
     this.context = context;
 }
示例#8
0
 protected BaseController()
 {
     this.db = new ChushkaContext();
 }
示例#9
0
 public ProductsService(ChushkaContext context)
 {
     this.context = context;
 }
示例#10
0
 public ProductService(ChushkaContext context)
     : base(context)
 {
 }
示例#11
0
 protected BaseService(ChushkaContext context)
 {
     this.context = context;
 }