Ejemplo n.º 1
0
        public int CopToSQL([FromQuery] string access_token)
        {
            int count = 0;

            if (access_token != "@bazavietnam")
            {
                return(count);
            }
            var fb = new FirebaseBusinessRepository(new FirebaseFactory(_appSettings));

            foreach (var t in fb.GetBusinesses(new Paging {
                Limit = 100
            }))
            {
                count++;
                _businessService.Create(t);
            }
            return(count);
        }
Ejemplo n.º 2
0
        public IActionResult Register([FromBody] BusinessDto businessDto)
        {
            Business business = _mapper.Map <Business>(businessDto);

            try
            {
                _businessService.Create(business, businessDto.Password);
                return(Ok());
            }
            catch (ValidationException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> CreateOrganisation(CreateOrganisationViewModel model)
        {
            string userId = User.Identity.GetUserId();
            var    user   = await _userManager.FindByIdAsync(userId);

            Business org = new Business
            {
                Name  = model.Name,
                Users = new List <User> {
                    user
                }
            };

            _businessService.Create(org);
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public ActionResponseModel Post([FromBody] BusinessRegisterModel registerBusiness)
        {
            ActionResponseModel response = new ActionResponseModel();

            response.Error = new List <string>();
            try
            {
                if (_personnelService.GetByEmail(registerBusiness.PersonnelEmail) != null ||
                    _userService.GetByEmail(registerBusiness.PersonnelEmail) != null)
                {
                    response.Error.Add("Email already used");
                }

                if (_businessService.FindByName(registerBusiness.Name) != null)
                {
                    response.Error.Add("Business name already used");
                }


                if (response.Error.Count > 0)
                {
                    response.Success = false;
                }
                else
                {
                    //Register business
                    var businessId = _businessService.Create(registerBusiness.ToBusinessDBModel());
                    //business admin add
                    _personnelService.Create(businessId, registerBusiness.ToPersonnelDBModel());
                    response.Success = true;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error.Add(ex.Message);
            }

            return(response);
        }
Ejemplo n.º 5
0
        public ApiResponse RegisterAdmin([FromForm] Agent agent)
        {
            ApiResponse response = new ApiResponse();

            if (string.IsNullOrWhiteSpace(agent.password))
            {
                response.msg = "Password not provided";
                return(response);
            }

            if (agent.password != agent.password_confirmation)
            {
                response.msg = "Passwords are mismatched";
                return(response);
            }
            agent.name          = string.IsNullOrWhiteSpace(agent.name) ? agent.last_name + " " + agent.first_name : agent.name;
            agent.business_name = agent.business_name ?? "";
            agent.business_name = agent.business_name.Trim();
            if (string.IsNullOrWhiteSpace(agent.business_name))
            {
                response.msg = "Business name required";
                return(response);
            }

            agent.email = agent.email ?? "";
            agent.email = agent.email.Trim().ToLower();
            if (string.IsNullOrWhiteSpace(agent.email) || !agent.email.Contains("@"))
            {
                response.msg = "Invalid email address";
                return(response);
            }
            if (!string.IsNullOrWhiteSpace(agent.facebook_access_token))
            {
                try
                {
                    var uri = "https://graph.facebook.com/v2.10/me?fields=id,name,email,age_range,first_name,gender,last_name,picture{url},birthday,address&access_token=" + agent.facebook_access_token;
                    var c   = Core.Helpers.WebHelper.HttpGetAsync <JObject>(uri).Result;
                    if (c != null && c["id"] != null)
                    {
                        agent.ext_id = (string)c["id"];
                        if (c["picture"] != null && c["picture"]["data"] != null && c["picture"]["data"]["url"] != null)
                        {
                            var imageUrl = ImagesService.UpsertImageStore((string)c["picture"]["data"]["url"], _appSettings.Value).Result;
                            agent.avatar = imageUrl;
                        }
                    }
                }
                catch (Exception ex) { }
            }
            var business = new Business
            {
                name   = agent.business_name,
                type   = "company",
                active = true,
                logo   = agent.avatar,
                email  = agent.email,
                ext_id = agent.ext_id,
                token  = agent.facebook_access_token
            };

            var businessCheck = _businessService.GetByEmail(agent.email);

            if (businessCheck == null || businessCheck.id == null)
            {
                agent.business_id = _businessService.Create(business);
            }
            else
            {
                agent.business_id = businessCheck.id;
            }
            agent.username     = agent.email;
            agent.login_status = "offline";
            agent.active       = true;
            agent.status       = "offline";
            agent.role         = "admin";

            //add hotline demo
            try
            {
                var uri  = _appSettings.Value.BaseUrls.ApiHotline + "api/PhoneAccounts/PhoneAccountNotUsingDemo";
                var obj  = Core.Helpers.WebHelper.HttpGetAsync <dynamic>(uri).Result;
                var bson = Core.Helpers.CommonHelper.JsonToBsonDocument((string)obj);
                foreach (var item in bson)
                {
                    agent.phone_account_id = item.Name;
                    break;
                }
            }
            catch (Exception ex) { }

            response.ok  = true;
            response.msg = agent.business_id;
            try
            {
                var current = _agentService.GetSingleOrDefaultByUserName(agent.username);
                if (current == null)
                {
                    response.data = _agentService.Create(agent);
                }
            }
            catch (Exception ex)
            {
                response.msg = ex.Message;
                throw ex;
            }

            return(response);
        }