Beispiel #1
0
        public OperationResult <IUserDto> AddWinningAmount(string emailId, int betAmount, decimal multiply)
        {
            OperationResult <IUserDto> returnValue = null;

            try
            {
                IUserDac userDac         = (IUserDac)DacFactory.Instance.Create(DacType.UserDac);
                IUserDto returnedUserDto = userDac.AddWinningAmount(emailId, betAmount, multiply);
                if (returnedUserDto != null)
                {
                    returnValue = OperationResult <IUserDto> .CreateSuccessResult(returnedUserDto, Constants.UserMessage.Reterived);
                }
                else
                {
                    returnValue = OperationResult <IUserDto> .CreateFailureResult(Constants.UserMessage.InsertionFialed);
                }
            }
            catch (DacException dacEx)
            {
                returnValue = OperationResult <IUserDto> .CreateErrorResult(dacEx.Message, dacEx.StackTrace);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                returnValue = OperationResult <IUserDto> .CreateErrorResult(ex.Message, ex.StackTrace);
            }

            return(returnValue);
        }
Beispiel #2
0
        public IList <IUserDto> SearchUser(string name, string contact, string email)
        {
            IList <IUserDto> retVal = null;

            try
            {
                using (CasinoAdminPortalEntities context = new CasinoAdminPortalEntities())
                {
                    IList <SearchPlayer_Result> userList = new List <SearchPlayer_Result>();
                    userList = (IList <SearchPlayer_Result>)context.SearchPlayer(name,
                                                                                 contact,
                                                                                 email).ToList();
                    if (userList.Count > 0)
                    {
                        retVal = new List <IUserDto>();
                        foreach (var user in userList)
                        {
                            IUserDto userDto = (IUserDto)DtoFactory.Instance.Create(DtoType.UserDto);
                            EntityConverter.FillDtoFromEntity(user, userDto);
                            retVal.Add(userDto);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DacException(ex.Message);
            }
            return(retVal);
        }
Beispiel #3
0
        public IUserDto AddWinningAmount(string emailId, int betAmount, decimal multiply)
        {
            IUserDto createUserRetval = null;

            try
            {
                using (CasinoAdminPortalEntities context = new CasinoAdminPortalEntities())
                {
                    Player playerDetails = context.Players.FirstOrDefault(item => item.EmailId == emailId);

                    if (playerDetails != null)
                    {
                        playerDetails.AccountBalance += (decimal)(betAmount * multiply);
                        playerDetails.BlockedAmount   = 0;
                        if (context.SaveChanges() > 0)
                        {
                            createUserRetval = (IUserDto)DtoFactory.Instance.Create(DtoType.UserDto);
                            EntityConverter.FillDtoFromEntity(playerDetails, createUserRetval);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DacException(ex.Message);
            }
            return(createUserRetval);
        }
Beispiel #4
0
        public IUserDto BlockAmount(string emailId, int amount)
        {
            IUserDto createUserRetval = null;
            decimal  amountD          = (decimal)amount;

            try
            {
                using (CasinoAdminPortalEntities context = new CasinoAdminPortalEntities())
                {
                    Player playerDetails = context.Players.FirstOrDefault(item => item.EmailId == emailId);
                    if (playerDetails != null && playerDetails.AccountBalance < amountD)
                    {
                        createUserRetval = (IUserDto)DtoFactory.Instance.Create(DtoType.UserDto);
                        EntityDataModel.EntityConverter.FillDtoFromEntity(playerDetails, createUserRetval);
                    }
                    else
                    {
                        playerDetails.BlockedAmount   = amount;
                        playerDetails.AccountBalance -= amountD;
                        if (context.SaveChanges() > 0)
                        {
                            createUserRetval = (IUserDto)DtoFactory.Instance.Create(DtoType.UserDto);
                            EntityDataModel.EntityConverter.FillDtoFromEntity(playerDetails, createUserRetval);
                        }
                    }
                }
            }
            catch (Exception ex) {
                ExceptionManager.HandleException(ex);
                throw new DacException(ex.Message);
            }
            return(createUserRetval);
        }
Beispiel #5
0
        private async Task<Email> BuildEmail(IUserDto user, TemplateType templateType, string token)
        {
            var email = new Email { Subject = String.Empty };
            var bodyBuilder = new StringBuilder(200);

            using (StreamReader reader = _templateProvider.GetTemplate(templateType))
            {
                string line = await reader.ReadLineAsync();
                for (int i = 0; line != null; i++)
                {
                    if (i == 0)
                    {
                        email.Subject = ReplaceMetaTagsWithUserData(line, user, token);
                    }
                    else
                    {
                        bodyBuilder.AppendLine(ReplaceMetaTagsWithUserData(line, user, token));
                    }

                    line = await reader.ReadLineAsync();
                }
            }

            email.Body = bodyBuilder.ToString();
            return email;
        }
Beispiel #6
0
        public IUserDto CreateUser(IUserDto userDto)
        {
            IUserDto createUserRetval = null;

            try
            {
                using (CasinoAdminPortalEntities context = new CasinoAdminPortalEntities())
                {
                    Player player = new Player();
                    userDto.BlockedAmount  = 0;
                    userDto.AccountBalance = 500;
                    EntityConverter.FillEntityFromDto(userDto, player);
                    context.Players.Add(player);
                    if (context.SaveChanges() > 0)
                    {
                        userDto.PlayerId = player.PlayerId;
                        createUserRetval = userDto;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DacException(ex.Message);
            }
            return(createUserRetval);
        }
Beispiel #7
0
        public ResultMessage Reject(RejectDto rejectModel, IUserDto user)
        {
            try
            {
                var product = _unitOfWork.ProductsRepository.GetById(rejectModel.Id);
                if (product == null)
                {
                    return(new ResultMessage
                    {
                        Status = HttpStatusCode.BadRequest,
                    });
                }

                product.UpdatedAt    = DateTime.Now;
                product.IsActive     = false;
                product.RejectReason = rejectModel.RejectReason;
                product.UpdatedBy    = user.Id;

                _unitOfWork.ProductsRepository.Update(product);
                _unitOfWork.Commit();
                return(new ResultMessage
                {
                    Status = HttpStatusCode.OK
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage
                {
                    Status = HttpStatusCode.InternalServerError
                });
            }
        }
Beispiel #8
0
        public OperationResult <IUserDto> GetUserByContactNumber(string contactNumber)
        {
            OperationResult <IUserDto> getUserReturnValue = null;

            try
            {
                IUserDac userDac         = (IUserDac)DacFactory.Instance.Create(DacType.UserDac);
                IUserDto returnedUserDto = userDac.GetUserByContactNumber(contactNumber);
                if (returnedUserDto != null)
                {
                    getUserReturnValue = OperationResult <IUserDto> .CreateSuccessResult(returnedUserDto, Constants.UserMessage.Reterived);
                }
                else
                {
                    getUserReturnValue = OperationResult <IUserDto> .CreateFailureResult(Constants.UserMessage.InsertionFialed);
                }
            }
            catch (DacException dacEx)
            {
                getUserReturnValue = OperationResult <IUserDto> .CreateErrorResult(dacEx.Message, dacEx.StackTrace);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                getUserReturnValue = OperationResult <IUserDto> .CreateErrorResult(ex.Message, ex.StackTrace);
            }

            return(getUserReturnValue);
        }
Beispiel #9
0
 public ResultMessage DeleteProgram(int id, IUserDto user)
 {
     try
     {
         var program = _unitOfWork.OTrainingProgramsRepository.GetById(id);
         if (program == null)
         {
             return(new ResultMessage()
             {
                 Status = HttpStatusCode.NotFound
             });
         }
         _unitOfWork.OTrainingProgramsRepository.Delete(id);
         _attachmentsManager.Delete(program.ProfilePicture);
         _unitOfWork.Commit();
         return(new ResultMessage()
         {
             Status = HttpStatusCode.OK
         });
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, string.Empty);
         return(new ResultMessage
         {
             Status = HttpStatusCode.InternalServerError
         });
     }
 }
Beispiel #10
0
        public async Task SendResetUserPasswordEmailAsync(IUserDto user)
        {
            string resetPasswordToken = await _userManager.GeneratePasswordResetTokenAsync(user.UserId);

            Email email = await _emailBuilder.BuildResetPasswordEmailAsync(user, resetPasswordToken);

            await _userManager.SendEmailAsync(user.UserId, email.Subject, email.Body);
        }
Beispiel #11
0
 public string SaveNewUser(IUserDto user)
 {
     if (CheckLogin(user.Login)) return "UserName is alredy registered";
     if (CheckEmail(user.EMail)) return "Email is alredy registered";
     user.Password = PasswordHashHelper.CreateHash(user.Password);
     dao.SaveUser(user);
     return string.Empty;
 }
Beispiel #12
0
        public async Task UpdateAsync(IUserDto user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            await _context.SaveChangesAsync();
        }
Beispiel #13
0
        public async Task CreateAsync(IUserDto user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            _context.Users.Add((UserDto)user);
            await _context.SaveChangesAsync();
        }
Beispiel #14
0
 public IUserClaimDto Map(IUserDto userDto, Claim claim)
 {
     return new UserClaimDto
     {
         Type = claim.Type,
         Value = claim.Value,
         ValueType = claim.ValueType,
         User = (UserDto)userDto
     };
 }
Beispiel #15
0
 public bool SaveUser(IUserDto user)
 {
     var userDb = provider.User.FirstOrDefault(u => u.UserName == user.Login);
     userDb.About = user.About;
     userDb.EMail = user.EMail;
     userDb.Foto = user.Foto;
     userDb.Location = user.Location;
     userDb.Skype = user.Skype;
     userDb.Name = user.Name;
     return ((DbContext)provider).SaveChanges() == 0;
 }
Beispiel #16
0
 public UserDto(IUserDto item)
 {
     if (item != null)
     {
         Id                = item.Id;
         Name              = item.Name;
         Phone             = item.Phone;
         CommunicationType = item.CommunicationType;
         Comment           = item.Comment;
         Vip               = item.Vip;
     }
 }
Beispiel #17
0
 public Task BanUser(IUserDto user)
 {
     return(Task.Run(() =>
     {
         lock (_bannedUsersLockObj)
         {
             _unbanTimers.Add(new Timer(callback => { UnBanUser(user.Account.Login); }, null, 120_000, Timeout.Infinite));
             _bannedUsers.Add(user.Account.Login);
         }
         _logger.LogWarning($"user {user.Account.Login} banned for 3 minutes!");
     }));
 }
Beispiel #18
0
        public async Task SendUserRegistrationConfirmationEmailAsync(IUserDto user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            string token = await _userManager.GenerateEmailConfirmationTokenAsync(user.UserId);

            Email email = await _emailBuilder.BuildRegsitrationConfirmationEmailAsync(user, token);

            await _userManager.SendEmailAsync(user.UserId, email.Subject, email.Body);
        }
Beispiel #19
0
 public Task DisactivateUser(IUserDto user)
 {
     return(Task.Run(() =>
     {
         IUserDto us;
         lock (_usersLockObj)
         {
             us = _users.Find(u => u.Account.Login == user.Account.Login);
         }
         us.Disactivate();
         _logger.LogWarning($"user {us.Account.Login} disactivated!");
     }));
 }
Beispiel #20
0
 /// <summary>
 /// Gets the user context from a session token.
 /// </summary>
 /// <param name="sessionToken">The session token.</param>
 /// <returns></returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public IUserContext GetUserContext(string sessionToken)
 {
     using (OpenAccessContext context = this.NewContext())
     {
         IUserDto user = this.GetUserInfo(context, sessionToken);
         if (user == null)
         {
             throw new ArgumentException("Invalid session Token");
         }
         this.SessionManager.UpdateSession(context, sessionToken);
         return(new UserContext(user));
     }
 }
Beispiel #21
0
        public ResultMessage Reject(RejectDto rejectDto, IUserDto user)
        {
            _logger.LogInformation($"START: Article.Reject: Id:{rejectDto.Id}");

            var validationResult = _rejectValidator.Validate(rejectDto);

            if (!validationResult.IsValid)
            {
                return(new ResultMessage
                {
                    Status = HttpStatusCode.BadRequest,
                    ValidationMessages = validationResult.GetErrorsList()
                });
            }
            try
            {
                var articleData = _unitOfWork.ArticlesRepository.GetById(rejectDto.Id);
                if (articleData == null)
                {
                    _logger.LogInformation($"END: Article.Reject: Id:{rejectDto.Id} --NotFound");

                    return(new ResultMessage
                    {
                        Status = HttpStatusCode.NotFound,
                    });
                }

                articleData.UpdatedAt    = DateTime.Now;
                articleData.UpdatedBy    = user.Id;
                articleData.RejectReason = rejectDto.RejectReason;
                articleData.IsActive     = false;

                _unitOfWork.ArticlesRepository.Update(articleData);
                _unitOfWork.Commit();
                _logger.LogInformation($"END: Article.Reject: Id:{rejectDto.Id} --SUCCESS");

                return(new ResultMessage
                {
                    Status = HttpStatusCode.OK,
                    Data = true
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage
                {
                    Status = HttpStatusCode.InternalServerError
                });
            }
        }
Beispiel #22
0
 public static User MapDtoToUser(IUserDto src)
 {
     if (src == null)
     {
         return(null);
     }
     return(new User
     {
         Id = src.Id,
         Name = src.Name,
         AdGuid = src.AdGuid,
         DepartmentId = src.DepartmentId
     });
 }
Beispiel #23
0
 public static User MapIUserDtoToUser(IUserDto userDto)
 {
     return new User()
     {
         Name = userDto.Name,
         Foto = userDto.Foto,
         Login = userDto.Login,
         Password = userDto.Password,
         EMail = userDto.EMail,
         About = userDto.About,
         Location = userDto.Location,
         Skype = userDto.Skype
     };
 }
Beispiel #24
0
        public ResultMessage Delete(int id, IUserDto user)
        {
            try
            {
                _logger.LogInformation($"START: Article.Delete: Id:{id}");

                var article = _unitOfWork.ArticlesRepository.GetById(id);
                if (article == null || article.IsDraft)
                {
                    _logger.LogInformation($"END: Article.Delete: Id:{id} -- NOTFOUND");

                    return(new ResultMessage
                    {
                        Status = HttpStatusCode.NotFound
                    });
                }

                if (user.IsAdmin || (user.Id == article.CreatedBy && (!article.IsActive.HasValue || !article.IsActive.Value)))
                {
                    article.UpdatedAt = DateTime.Now;
                    article.UpdatedBy = user.Id;
                    article.IsDraft   = true;
                    _unitOfWork.ArticlesRepository.Update(article);
                    _unitOfWork.Commit();
                    _logger.LogInformation($"END: Article.Delete: Id:{id}  --SUCCESS");
                    return(new ResultMessage
                    {
                        Status = HttpStatusCode.OK
                    });
                }
                else
                {
                    _logger.LogInformation($"END: Article.Delete: Id:{id} -- UNAuthorized");

                    return(new ResultMessage
                    {
                        Status = HttpStatusCode.Unauthorized
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage
                {
                    Status = HttpStatusCode.InternalServerError
                });
            }
        }
Beispiel #25
0
        public ResultMessage Delete(int id, IUserDto user)
        {
            try
            {
                var product = _unitOfWork.ProductsRepository.GetById(id);
                if (product == null)
                {
                    return new ResultMessage
                           {
                               Status = HttpStatusCode.NotFound
                           }
                }
                ;

                if (!user.IsAdmin && product.CreatedBy != user.Id)
                {
                    return new ResultMessage
                           {
                               Status    = HttpStatusCode.Unauthorized,
                               ErrorCode = (int)ProductsErrorsCodeEnum.ProductsNotFoundError
                           }
                }
                ;

                //delete attachments
                var productFolder = product.SubFolderName;
                if (!string.IsNullOrEmpty(productFolder))
                {
                    _attachmentsManager.DeleteFolder(productFolder, AttachmentTypesEnum.Products);
                }


                _unitOfWork.ProductsRepository.Delete(id);
                _unitOfWork.Commit();
                return(new ResultMessage()
                {
                    Status = HttpStatusCode.OK
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage
                {
                    Status = HttpStatusCode.InternalServerError,
                    ErrorCode = (int)ProductsErrorsCodeEnum.ProductsDeleteError
                });
            }
        }
Beispiel #26
0
        public async Task<Email> BuildResetPasswordEmailAsync(IUserDto user, string resetPasswordToken)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (String.IsNullOrWhiteSpace(resetPasswordToken))
            {
                throw new ArgumentNullException("resetPasswordToken");
            }

            Email email = await BuildEmail(user, TemplateType.ResetPassword, resetPasswordToken);
            return email;
        }
Beispiel #27
0
        public IList <IUserDto> GetAllUsers()
        {
            IList <IUserDto> userDtoList = new List <IUserDto>();

            using (CasinoAdminPortalEntities context = new CasinoAdminPortalEntities())
            {
                foreach (Player player in context.Players)
                {
                    IUserDto userDto = (IUserDto)DtoFactory.Instance.Create(DtoType.UserDto);
                    EntityConverter.FillDtoFromEntity(player, userDto);
                    userDtoList.Add(userDto);
                }
                return(userDtoList);
            }
        }
Beispiel #28
0
        public async Task<Email> BuildRegsitrationConfirmationEmailAsync(IUserDto user, string confirmEmailToken)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (String.IsNullOrWhiteSpace(confirmEmailToken))
            {
                throw new ArgumentNullException("confirmEmailToken");
            }

            Email email = await BuildEmail(user, TemplateType.EmailConfirmation, confirmEmailToken);
            return email;
        }
Beispiel #29
0
        private string ReplaceMetaTagsWithUserData(string line, IUserDto userDto, string token)
        {
            line = line.Replace("{{FirstName}}", userDto.FirstName)
                       .Replace("{{LastName}}", userDto.LastName)
                       .Replace("{{Email}}", userDto.Email)
                       .Replace("{{Token}}", token)
                       .Replace("{{UserId}}", userDto.UserId.ToString(CultureInfo.InvariantCulture));

            if (userDto.Group != null)
            {
                line = line
                    .Replace("{{GroupNumber}}", userDto.Group.GroupNumber.ToString(CultureInfo.InvariantCulture))
                    .Replace("{{GroupYear}}", userDto.Group.Year.ToString(CultureInfo.InvariantCulture));
            }

            return line;
        }
Beispiel #30
0
 /// <summary>
 /// Logins a user into the system.
 /// </summary>
 /// <param name="login">The login.</param>
 /// <param name="password">The password.</param>
 /// <returns></returns>
 /// <exception cref="System.ArgumentException">Login invalid</exception>
 public IUserDto Login(string login, string password)
 {
     using (OpenAccessContext context = this.NewContext())
     {
         object user = this.GetUserByLoginPass(context, login, password);
         if (user == null)
         {
             throw new ArgumentException("Login invalid");
         }
         IUserDto result = (IUserDto)ObjectProxyFactory.MapTo(this.UserDtoType, user);
         result.Password     = null;
         result.SessionToken = this.SessionManager.NewSessionToken();
         this.SessionManager.AddSessionForUser(context, result.UserId.Value, result.SessionToken);
         context.SaveChanges();
         return(result);
     }
 }
Beispiel #31
0
        public ResultMessage InsertProgram(OTrainingProgramDto programDto, IUserDto user)
        {
            var validationResult = _programValidator.Validate(programDto);

            if (!validationResult.IsValid)
            {
                return new ResultMessage
                       {
                           Status             = HttpStatusCode.BadRequest,
                           ValidationMessages = validationResult.GetErrorsList()
                       }
            }
            ;

            try
            {
                var newProgram = programDto.Adapt <OTrainingPrograms>();

                newProgram.CreatedAt      = DateTime.Now;
                newProgram.CreatedBy      = user.Id;
                newProgram.ProfilePicture = _attachmentsManager.Save(new SavedFileDto
                {
                    File           = programDto.ProfilePictureFile,
                    attachmentType = AttachmentTypesEnum.OTrainingProgram,
                    CanChangeName  = true
                });

                _unitOfWork.OTrainingProgramsRepository.Insert(newProgram);
                _unitOfWork.Commit();
                return(new ResultMessage()
                {
                    Status = HttpStatusCode.OK
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage()
                {
                    Status = HttpStatusCode.InternalServerError
                });
            }
        }
Beispiel #32
0
        /// <summary>
        /// Gets the user information.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sessionToken">The session token.</param>
        /// <returns></returns>
        protected virtual IUserDto GetUserInfo(OpenAccessContext context, string sessionToken)
        {
            ISessionDto sessionData = this.SessionManager.GetSessionData(context, sessionToken);

            if (sessionData == null)
            {
                return(null);
            }
            object user = this.GetUserById(context, sessionData.UserId);

            if (user == null)
            {
                this.SessionManager.RemoveSession(context, sessionToken);
                context.SaveChanges();
                return(null);
            }
            IUserDto result = (IUserDto)ObjectProxyFactory.MapTo(this.UserDtoType, user);

            result.Password     = null;
            result.SessionToken = sessionData.SessionToken;
            return(result);
        }
Beispiel #33
0
        public OperationResult <IUserDto> CreateUser(IUserDto userDto)
        {
            OperationResult <IUserDto> createUserReturnValue = null;

            try
            {
                EmployeePortalValidationResult validationResult = Validator <UserValidator, IUserDto> .Validate(userDto, Constants.UserMessage.CreateUserEmail);

                if (!validationResult.IsValid)
                {
                    createUserReturnValue = OperationResult <IUserDto> .CreateFailureResult(validationResult);
                }
                else
                {
                    IUserDac employeeDac     = (IUserDac)DacFactory.Instance.Create(DacType.UserDac);
                    IUserDto returnedUserDto = employeeDac.CreateUser(userDto);
                    if (returnedUserDto != null)
                    {
                        createUserReturnValue = OperationResult <IUserDto> .CreateSuccessResult(returnedUserDto, Constants.UserMessage.Usercreatedsuccessfully);
                    }
                    else
                    {
                        createUserReturnValue = OperationResult <IUserDto> .CreateFailureResult(Constants.UserMessage.InsertionFialed);
                    }
                }
            }
            catch (DacException dacEx)
            {
                createUserReturnValue = OperationResult <IUserDto> .CreateErrorResult(dacEx.Message, dacEx.StackTrace);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                createUserReturnValue = OperationResult <IUserDto> .CreateErrorResult(ex.Message, ex.StackTrace);
            }

            return(createUserReturnValue);
        }
        public ActionResult CreateUser(UserModel responseModel)
        {
            IUserDto           userDtoToCreate = (IUserDto)DtoFactory.Instance.Create(DtoType.UserDto);
            HttpPostedFileBase file            = Request.Files["ImageData"];

            responseModel.IdentityProof = ConvertToBytes(file);
            if (ModelState.IsValid)
            {
                DTOConverter.FillDTOFromViewModel(userDtoToCreate, responseModel);
                OperationResult <IUserDto> resultCreate = _userFacade.CreateUser(userDtoToCreate);
                if (resultCreate.ValidationResult != null && resultCreate.ValidationResult.Errors != null)
                {
                    IList <EmployeePortalValidationFailure> resultFail = resultCreate.ValidationResult.Errors;
                    foreach (var item in resultFail)
                    {
                        ModelState.AddModelError(item.PropertyName, item.ErrorMessage);
                    }
                    return(View());
                }
                return(View("../Home/Index"));
            }
            return(View());
        }
Beispiel #35
0
        public IUserDto GetUserByContactNumber(string contactNumber)
        {
            IUserDto createUserRetval = null;

            try
            {
                using (CasinoAdminPortalEntities context = new CasinoAdminPortalEntities())
                {
                    Player playerDetails = context.Players.FirstOrDefault(item => item.ContactNumber == contactNumber);

                    if (playerDetails != null)
                    {
                        createUserRetval = (IUserDto)DtoFactory.Instance.Create(DtoType.UserDto);
                        EntityConverter.FillDtoFromEntity(playerDetails, createUserRetval);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DacException(ex.Message);
            }
            return(createUserRetval);
        }
Beispiel #36
0
        public OperationResult <IUserDto> CreateUser(IUserDto userDto)
        {
            IUserBdc userBdc = (IUserBdc)BdcFactory.Instance.Create(BdcType.UserBdc);

            return(userBdc.CreateUser(userDto));
        }
Beispiel #37
0
 public bool SaveChanges(IUserDto user)
 {
     return dao.SaveUser(user);
 }
Beispiel #38
0
 private static IUserIdentityModel CreateIdentityFromDto(IUserDto userDto)
 {
     return new User
     {
         Email = userDto.Email,
         UserId = userDto.UserId,
     };
 }
Beispiel #39
0
 private User Map(IUserDto user)
 {
     return new User
     {
         UserId = user.UserId,
         Email = user.Email,
         FirstName = user.FirstName,
         LastName = user.LastName,
         Group = user.GroupId.HasValue ? new Group
         {
             GroupId = user.GroupId.Value
         } : null
     };
 }
Beispiel #40
0
 public Task <bool> CheckIfUserBanned(IUserDto user)
 {
     return(Task.FromResult <bool>(_bannedUsers.Contains(user.Account.Login)));
 }
Beispiel #41
0
        public ResultMessage Insert(ProductsDto newProductDto, IUserDto user)
        {
            var validationResult = _validator.Validate(newProductDto);

            if (!validationResult.IsValid)
            {
                return new ResultMessage
                       {
                           Status             = HttpStatusCode.BadRequest,
                           ValidationMessages = validationResult.GetErrorsList()
                       }
            }
            ;

            try
            {
                var productFolderName = Guid.NewGuid().ToString();

                var newProduct = newProductDto.Adapt <DBModels.Products>();
                newProduct.IsActive      = null;
                newProduct.CreatedAt     = DateTime.Now;
                newProduct.CreatedBy     = user.Id;
                newProduct.SubFolderName = productFolderName;

                var sliderDto = new SliderDto
                {
                    attachmentType = AttachmentTypesEnum.Products,
                    Items          = newProductDto.UpdatedImages,
                    SubFolderName  = productFolderName
                };

                if (sliderDto.Items != null && sliderDto.Items.Count > 0)
                {
                    newProduct.ProfilePicture = _sliderManager.GetProfilePicturePath(sliderDto);
                }

                if (user.IsAdmin)
                {
                    newProduct.IsActive = true;
                }

                _unitOfWork.ProductsRepository.Insert(newProduct);
                _unitOfWork.Commit();

                sliderDto.ParentId = newProduct.Id;
                _sliderManager.Add(sliderDto);

                return(new ResultMessage
                {
                    Status = HttpStatusCode.OK,
                    Data = GetById(newProduct.Id).Data
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage()
                {
                    ErrorCode = (int)ProductsErrorsCodeEnum.ProductsInsertError,
                    Status = HttpStatusCode.InternalServerError
                });
            }
        }
Beispiel #42
0
        public ResultMessage Insert(ArticleAddDto article, IUserDto user)
        {
            _logger.LogInformation($"START: Article.Insert: Name:{article.Name}");

            var validationResult = _addValidator.Validate(article);

            if (!validationResult.IsValid)
            {
                _logger.LogInformation($"END: Article.Insert: Name:{article.Name}  --VALIDATION");
                return(new ResultMessage
                {
                    Status = HttpStatusCode.BadRequest,
                    ValidationMessages = validationResult.GetErrorsList()
                });
            }
            try
            {
                var articleEntity = article.Adapt <DBModels.Articles>();
                articleEntity.CreatedAt = DateTime.Now;
                articleEntity.CreatedBy = user.Id;

                var articleFolderName = Guid.NewGuid().ToString();

                var sliderDto = new SliderDto
                {
                    attachmentType = AttachmentTypesEnum.Articles,
                    Items          = article.UpdatedImages,
                    SubFolderName  = articleFolderName
                };

                if (sliderDto.Items.Count > 0)
                {
                    articleEntity.ProfilePicture = _sliderManager.GetProfilePicturePath(sliderDto);
                }

                articleEntity.SubFolderName = articleFolderName;
                articleEntity.Images        = null;
                articleEntity.IsActive      = null;

                if (user.IsAdmin)
                {
                    articleEntity.IsActive = true;
                }

                _unitOfWork.ArticlesRepository.Insert(articleEntity);
                _unitOfWork.Commit();

                sliderDto.ParentId = articleEntity.Id;
                _sliderManager.Add(sliderDto);

                _logger.LogInformation($"END: Article.Insert: Name:{article.Name}  --SUCCESS");

                return(new ResultMessage
                {
                    Status = HttpStatusCode.OK
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage()
                {
                    ErrorCode = (int)ProductsErrorsCodeEnum.ProductsInsertError,
                    Status = HttpStatusCode.InternalServerError
                });
            }
        }
Beispiel #43
0
        public ResultMessage Update(ArticleAddDto article, int articleId, IUserDto user)
        {
            _logger.LogInformation($"START: Article.Update: Name:{article.Name}");

            var validationResult = _addValidator.Validate(article);

            if (!validationResult.IsValid)
            {
                _logger.LogInformation($"END: Article.Update: Id:{articleId} -- VALIDATION");
                return(new ResultMessage
                {
                    Status = HttpStatusCode.BadRequest,
                    ValidationMessages = validationResult.GetErrorsList()
                });
            }
            try
            {
                var articleData = _unitOfWork.ArticlesRepository.GetById(articleId);
                if (articleData == null || articleData.IsDraft)
                {
                    _logger.LogInformation($"END: Article.Update: Id:{articleId} -- NOTFOUND");
                    return(new ResultMessage
                    {
                        Status = HttpStatusCode.NotFound,
                    });
                }


                if (user.IsAdmin || (user.Id == articleData.CreatedBy && (!articleData.IsActive.HasValue || !articleData.IsActive.Value)))
                {
                    article.Adapt(articleData, typeof(ArticleAddDto), typeof(DBModels.Articles));
                    articleData.UpdatedAt = DateTime.Now;
                    articleData.UpdatedBy = user.Id;

                    var sliderDto = new SliderDto
                    {
                        attachmentType = AttachmentTypesEnum.Articles,
                        Items          = article.UpdatedImages ?? new List <SliderItemDto>(),
                        SubFolderName  = articleData.SubFolderName,
                        ParentId       = articleId
                    };

                    //check profile picture
                    if (sliderDto.Items.Count > 0)
                    {
                        articleData.ProfilePicture = _sliderManager.GetProfilePicturePath(sliderDto, article.ProfilePicture);
                    }

                    _unitOfWork.ArticlesRepository.Update(articleData);
                    _unitOfWork.Commit();

                    // update files
                    if (sliderDto.Items.Count > 0)
                    {
                        _sliderManager.Update(sliderDto);
                    }

                    _logger.LogInformation($"END: Article.Update: ID:{articleId} --SUCCESS");

                    return(new ResultMessage
                    {
                        Status = HttpStatusCode.OK
                    });
                }
                else
                {
                    _logger.LogInformation($"END: Article.Update: Id:{articleId} -- UNAuthorized");

                    return(new ResultMessage
                    {
                        Status = HttpStatusCode.Unauthorized
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage
                {
                    Status = HttpStatusCode.InternalServerError
                });
            }
        }
Beispiel #44
0
        public ResultMessage Update(ProductsDto product, int id, IUserDto user)
        {
            var validationResult = _validator.Validate(product);

            if (!validationResult.IsValid)
            {
                return new ResultMessage
                       {
                           Status             = HttpStatusCode.BadRequest,
                           ValidationMessages = validationResult.GetErrorsList()
                       }
            }
            ;

            try
            {
                var oldProduct = _unitOfWork.ProductsRepository.GetById(id);

                if (oldProduct == null)
                {
                    return new ResultMessage
                           {
                               Status    = HttpStatusCode.NotFound,
                               ErrorCode = (int)ProductsErrorsCodeEnum.ProductsNotFoundError
                           }
                }
                ;

                if (!user.IsAdmin && oldProduct.CreatedBy != user.Id)
                {
                    return new ResultMessage
                           {
                               Status    = HttpStatusCode.NotFound,
                               ErrorCode = (int)ProductsErrorsCodeEnum.ProductsNotFoundError
                           }
                }
                ;

                oldProduct.Name = product.Name;
                if (product.ProfilePictureFile != null)
                {
                    oldProduct.ProfilePicture = _attachmentsManager.Save(new SavedFileDto
                    {
                        attachmentType = AttachmentTypesEnum.Products,
                        CanChangeName  = true,
                        File           = product.ProfilePictureFile
                    });
                }

                oldProduct.IsActive = product.IsActive = null;
                if (user.IsAdmin)
                {
                    oldProduct.IsActive = true;
                }

                oldProduct.IsSpecial   = product.IsSpecial;
                oldProduct.Price       = product.Price;
                oldProduct.ExpDate     = product.ExpDate;
                oldProduct.Description = product.Description;
                oldProduct.CategoryId  = product.CategoryId;
                oldProduct.PhoneNumber = product.PhoneNumber;

                oldProduct.UpdatedBy = user.Id;
                oldProduct.UpdatedAt = DateTime.Now;

                var sliderDto = new SliderDto
                {
                    attachmentType = AttachmentTypesEnum.Products,
                    Items          = product.UpdatedImages ?? new List <SliderItemDto>(),
                    SubFolderName  = oldProduct.SubFolderName,
                    ParentId       = id
                };

                //check profile picture
                if (sliderDto.Items.Count > 0)
                {
                    oldProduct.ProfilePicture = _sliderManager.GetProfilePicturePath(sliderDto, oldProduct.ProfilePicture);
                }


                _unitOfWork.ProductsRepository.Update(oldProduct);
                _unitOfWork.Commit();

                // update files
                if (sliderDto.Items.Count > 0)
                {
                    _sliderManager.Update(sliderDto);
                }

                return(new ResultMessage
                {
                    Status = HttpStatusCode.OK,
                    Data = oldProduct.Adapt <ProductsDto>()
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage
                {
                    Status = HttpStatusCode.InternalServerError,
                    ErrorCode = (int)ProductsErrorsCodeEnum.ProductsUpdateError
                });
            }
        }
Beispiel #45
0
 public static User MapIUserDtoToUser(IUserDto userDto)
 {
     return new User()
     {
         UserName = userDto.Login,
         Name = userDto.Name,
         About = userDto.About,
         DateRegistration = DateTime.Now,
         EMail = userDto.EMail,
         Foto = userDto.Foto,
         Location = userDto.Location,
         Password = userDto.Password,
         Skype = userDto.Skype
     };
 }
Beispiel #46
0
        private async Task <IReadOnlyCollection <Claim> > GetClaimsAsync(string clientId, IUserDto user)
        {
            var claims = new List <Claim>();
            var client = await Task.Run(() => ClientService.GetClientByClientId(clientId));

            var userProfile =
                await Task.Run(() => BackingUserService.GetUserProfile(user.Key, client.UserProfileOriginator));

            //make sure user is within expected profile group

            if (userProfile == null)
            {
                return(claims);
            }

            claims.Add(new Claim(Constants.ClaimTypes.Subject, user.Key.ToString()));

            if (!string.IsNullOrWhiteSpace(user.Email.Address))
            {
                claims.Add(new Claim(Constants.ClaimTypes.Email, user.Email.Address));
                if (user.Email.Verified)
                {
                    claims.Add(new Claim(Constants.ClaimTypes.EmailVerified, user.Email.Address));
                }
            }

            if (!string.IsNullOrWhiteSpace(user.Mobile.FullNumber))
            {
                claims.Add(new Claim(Constants.ClaimTypes.PhoneNumber, user.Mobile.FullNumber));
                if (user.Mobile.Verified)
                {
                    claims.Add(new Claim(Constants.ClaimTypes.PhoneNumberVerified, user.Mobile.FullNumber));
                }
            }

            if (!string.IsNullOrWhiteSpace(userProfile.Body))
            {
                claims.Add(new Claim(Constants.ClaimTypes.Profile, userProfile.Body));
            }

            if (user.IsAdmin)
            {
                claims.Add(new Claim(Constants.ClaimTypes.Role, RoleTypeName.Admin));
            }

            return(claims);
        }