Exemplo n.º 1
0
        public ResponseModel<String> WebRegisterService(RegisterationRequest req, HttpRequestBase request)
        {            
            var response = new ResponseModel<String>();
            if (_db.Users.Any(x => x.Username == req.Username))
            {
                response.Status = 409;
                response.Message = "conflict";
                return response;
            }

            var guid = Guid.NewGuid().ToString();
            var user = new User
            {
                Username = req.Username,
                Password = EncryptionClass.Md5Hash(req.Password),
                Source = req.Source,
                isActive = "false",
                Type = req.Type,
                guid = Guid.NewGuid().ToString(),
                fixedGuid= Guid.NewGuid().ToString(),
                FirstName = req.FirstName,
                LastName = req.LastName,
                gender = "NA",
                ImageUrl = "NA"
            };
            _db.Users.Add(user);
            
            if (!Constants.NA.Equals(req.Referral))
            {
                new ReferralService().payReferralBonusAsync(req.Referral, req.Username,Constants.status_false);
            }
            if (req.Type == "client")
            {
                var dbClientDetails = new ClientDetail
                {
                    Username = req.Username,
                    CompanyName =  string.IsNullOrEmpty(req.CompanyName)?"NA":req.CompanyName
                };
                _db.ClientDetails.Add(dbClientDetails);
            }
            var dbValidateUserKey = new ValidateUserKey
            {
                Username = req.Username,
                guid = guid
            };

            _db.ValidateUserKeys.Add(dbValidateUserKey);

            try
            {
                _db.SaveChanges();
                var signalRHub = new SignalRHub();
                string totalProjects = "";
                string successRate = "";
                string totalUsers = _db.Users.Count().ToString(CultureInfo.InvariantCulture);
                string projectCategories = "";
                var hubContext = GlobalHost.ConnectionManager.GetHubContext<SignalRHub>();
                hubContext.Clients.All.updateBeforeLoginUserProjectDetails(totalProjects, successRate, totalUsers, projectCategories);
                SendAccountCreationValidationEmail.SendAccountCreationValidationEmailMessage(req.Username, guid, request);
            }
            catch (DbEntityValidationException e)
            {
                DbContextException.LogDbContextException(e);
                response.Status = 500;
                response.Message = "Internal Server Error !!!";
                return response;
            }

            response.Status = 200;
            response.Message = "success";
            response.Payload = "Account Created";

            return response;
        }
Exemplo n.º 2
0
        public ResponseModel<String> WebRegisterService(RegisterationRequest req, HttpRequestBase request)
        {
            var response = new ResponseModel<String>();
            if (_db.Users.Any(x => x.Username == req.Username))
            {
                response.Status = 409;
                response.Message = "conflict";
                return response;
            }

            var guid = Guid.NewGuid().ToString();
            var user = new User
            {
                Username = req.Username,
                Password = EncryptionClass.Md5Hash(req.Password),
                Source = req.Source,
                isActive = "false",
                Type = req.Type,
                guid = Guid.NewGuid().ToString(),
                FirstName = req.FirstName,
                LastName = req.LastName,
                gender = "NA",
                ImageUrl = "NA"
            };
            _db.Users.Add(user);

            if (!string.IsNullOrEmpty(req.Referral))
            {
                var dbRecommedBy = new RecommendedBy
                {
                    RecommendedFrom = req.Referral,
                    RecommendedTo = req.Username
                };
                _db.RecommendedBies.Add(dbRecommedBy);
            }
            if (req.Type == "client")
            {
                var dbClientDetails = new ClientDetail
                {
                    Username = req.Username,
                    CompanyName = req.CompanyName
                };
                _db.ClientDetails.Add(dbClientDetails);
            }
            var dbValidateUserKey = new ValidateUserKey
            {
                Username = req.Username,
                guid = guid
            };

            _db.ValidateUserKeys.Add(dbValidateUserKey);

            try
            {
                _db.SaveChanges();
                SendAccountCreationValidationEmail.SendAccountCreationValidationEmailMessage(req.Username, guid, request);
            }
            catch (DbEntityValidationException e)
            {
                DbContextException.LogDbContextException(e);
                response.Status = 500;
                response.Message = "Internal Server Error !!!";
                return response;
            }

            response.Status = 200;
            response.Message = "success";
            response.Payload = "Account Created";

            return response;
        }