Ejemplo n.º 1
0
        public static void Run(
            [QueueTrigger("azure", Connection = "AzureWebJobsStorage")]
            string message,
            ILogger log)
        {
            try
            {
                RSDbContext             context          = new RSDbContext();
                IMapper                 _mapper          = AutoMapperConfig.MapperConfig().CreateMapper();
                IRecommenceHobbyService _hobbyService    = new RecommenceHobbyService(new UnitOfWork(context));
                ICategoryService        _categoryService = new CategoryService(new UnitOfWork(context));
                IUserService            _userService     = new UserService(new UnitOfWork(context));
                IProductService         _productService  = new ProductService(new UnitOfWork(context));

                var recommence = JsonSerializer.Deserialize <Recommence>(message);

                var result = _hobbyService.RecommenceByHobbyGetListProduct(recommence);
                var userId = recommence.UserId;

                //create new category if not exist
                foreach (var item in result)
                {
                    var categoryId = item.CategoryId;
                    if (_categoryService.CheckCategory(categoryId))
                    {
                        CreateCategoryViewModel newCate = new CreateCategoryViewModel();
                        newCate.Code = categoryId;
                        _categoryService.Create(_mapper.Map <Category>(newCate));
                    }
                }

                //create products if not exist
                var products = _mapper.Map <IEnumerable <CreateProductViewModel> >(result)
                               .Select(x => _productService.Create(_mapper.Map <Product>(x)));

                //create new user if not exist
                CreateUserViewModel newUser = new CreateUserViewModel();
                newUser.Code = userId;
                _userService.Create(_mapper.Map <User>(newUser));

                //select list products'code
                IEnumerable <string> listCode = result.Select(x => x.Code);

                //create RecommenceHobbyModel to save database
                CreateRecommenceByHobbyViewModel hobbyViewModel = new CreateRecommenceByHobbyViewModel();
                var list = _mapper.Map <IEnumerable <ProductViewModel> >(products);
                hobbyViewModel.ProductRecommenceHobbies = list;
                hobbyViewModel.UserId = userId;
                var a = _mapper.Map <RecommenceHobby>(hobbyViewModel);
                _hobbyService.LoadAndUpdate(a);

///--------------------------------------------------------------------
///
            }
            catch (Exception ex)
            {
                log.LogError(ex.Message);
                throw;
            }
        }
Ejemplo n.º 2
0
 public bool Authenticate(string username, string password)
 {
     bool result = Membership.ValidateUser(username, password);
     if (result)
     {
         FormsAuthentication.SetAuthCookie(username, false);
         RSDbContext db = new RSDbContext();
         Member member =  db.Members.FirstOrDefault(m => m.UserName == username);
         HttpContext.Current.Session.Add("MemberGuid", member.MemberGuid);
     }
     return result;
 }
        public bool LogIn(string username, string password)
        {
            using (RSDbContext Db = new RSDbContext())
            {
                RSUser user = Db.Users.FirstOrDefault(u => u.Username == username);
                user.DependencyInjection();

                if (user == null) return false;
                if (!user.CheckPassword(password)) return false;

                HttpContext.Current.Response.Cookies[COOKIE_NAME][COOKIE_USERNAME] = user.Username;
                HttpContext.Current.Response.Cookies[COOKIE_NAME][COOKIE_PASSWORDHASH] = BitConverter.ToString(user.PasswordHash);
                HttpContext.Current.Response.Cookies[COOKIE_NAME].Expires = DateTime.Now.AddDays(30);

                CurrentUser = user;
                return true;
            }
        }
Ejemplo n.º 4
0
        public bool LogIn(string username, string password)
        {
            using (RSDbContext Db = new RSDbContext())
            {
                RSUser user = Db.Users.FirstOrDefault(u => u.Username == username);
                user.DependencyInjection();

                if (user == null)
                {
                    return(false);
                }
                if (!user.CheckPassword(password))
                {
                    return(false);
                }

                HttpContext.Current.Response.Cookies[COOKIE_NAME][COOKIE_USERNAME]     = user.Username;
                HttpContext.Current.Response.Cookies[COOKIE_NAME][COOKIE_PASSWORDHASH] = BitConverter.ToString(user.PasswordHash);
                HttpContext.Current.Response.Cookies[COOKIE_NAME].Expires = DateTime.Now.AddDays(30);

                CurrentUser = user;
                return(true);
            }
        }
Ejemplo n.º 5
0
        public static void SeedData()
        {
            RSDbContext context = new RSDbContext();

            Member member;
            Role[] roles;

            if (context.Members.Count() == 0)
            {
                member = new Member
                {
                    MemberGuid = Guid.NewGuid(),
                    UserName = "******",
                    Email = "*****@*****.**",
                    Profile = new Profile
                    {
                        FirstName = "Admin",
                        LastName = "Root",
                        Description = "Application Administrator",
                        Phone = "",
                        Address = "",
                        Building = "",
                        Floor = "",
                        Office = ""
                    },
                    Password = new Password
                    {
                        Hash = "BB595D807F9615796C9B99A52CE4E8F07347C899",
                        Salt = "sVGQGTu+CZH8axS6QWNMm3IZ6PdKA89HE2Ju3vs0LK8="
                    }

                };

                RoleSet user = new RoleSet { Name = "Users" };
                RoleSet powerUser = new RoleSet { Name = "Power Users" };
                RoleSet admin = new RoleSet { Name = "Administrators" };

                roles = new Role[] {
                    new Role { Name = "Can_Access_Application",
                        Description = "Can access this application",
                        },
                    new Role { Name = "Can_Access_Control_Panel",
                        Description = "Can access Control Panel",
                        },
                    new Role { Name = "Can_Access_Home_Controller",
                        Description = "Can access Control's Panel Home Page",
                        },
                    new Role { Name = "Can_Access_Member_Controller",
                        Description = "Can access Member Settings",
                        },
                    new Role { Name = "Can_Create_Member",
                        Description = "Can add members",
                        },
                    new Role { Name = "Can_Edit_Member",
                        Description = "Can edit member's details",
                        },
                    new Role { Name = "Can_Delete_Member",
                        Description = "Can remove members",
                        },
                    new Role { Name = "Can_Access_Role_Controller",
                        Description = "Can access Role Settings",
                        },
                    new Role { Name = "Can_Create_Role_Set",
                        Description = "Can add roles",
                        },
                    new Role { Name = "Can_Edit_Role_Set",
                        Description = "Can edit role's settings",
                        },
                    new Role { Name = "Can_Delete_Role_Set",
                        Description = "Can remove roles" }
                };

                int currentRoles = context.Roles.Count() > 0 ? (context.Roles.Count() - 1) : 0;

                foreach (Role role in roles)
                {
                    context.Roles.Add(role);
                }

                List<RoleSetting> adminRoles = new List<RoleSetting>();
                foreach (Role role in roles)
                {
                    RoleSetting roleValue = new RoleSetting();
                    roleValue.Role = role;
                    roleValue.IsActive = true;

                    adminRoles.Add(roleValue);
                }
                admin.Roles = adminRoles;

                List<RoleSetting> powerUserRoles = new List<RoleSetting>();
                foreach (Role role in roles)
                {
                    RoleSetting roleValue = new RoleSetting();
                    roleValue.Role = role;
                    roleValue.IsActive = true;

                    powerUserRoles.Add(roleValue);
                }
                powerUser.Roles = powerUserRoles;

                List<RoleSetting> userRoles = new List<RoleSetting>();
                foreach (Role role in roles)
                {
                    RoleSetting roleValue = new RoleSetting();
                    roleValue.Role = role;
                    roleValue.IsActive = false;

                    userRoles.Add(roleValue);
                }
                user.Roles = userRoles;

                foreach (RoleSet item in new RoleSet[] { admin, powerUser, user })
                {
                    context.RoleSets.Add(item);
                }

                member.RoleSet = admin;

                context.Members.Add(member);

                context.SaveChanges();
            }
        }
Ejemplo n.º 6
0
 public WebApiApplication()
 {
     Db = new RSDbContext();
     this.DependencyInjection();
 }
Ejemplo n.º 7
0
 public UnitOfWork(RSDbContext dbContext)
 {
     _dbContext = dbContext;
 }