Example #1
0
        public async Task <ModelBaseStatus> PostReferralCode(PostReferralCode PostReferralCode)
        {
            ModelBaseStatus output = new ModelBaseStatus();
            var             jwt    = _httpContextAccessor.HttpContext.User.FindFirst(p => p.Type == "access_token").Value;

            if (jwt != null)
            {
                _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwt);
                string apiUrl   = $"/api/v1/Brand/PostReferralCode";
                var    userInfo = JsonConvert.DeserializeObject <SumProfileResponseDTO>(_httpContextAccessor.HttpContext.User.FindFirst(p => p.Type == "UserInfomation").Value);
                PostReferralCode.UserId         = userInfo.UserId;
                PostReferralCode.ProductBrandId = userInfo.ProductBrandId;
                var json          = JsonConvert.SerializeObject(PostReferralCode, Formatting.Indented);
                var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
                var response      = await _client.PostAsync(apiUrl, stringContent);

                if (response.IsSuccessStatusCode)
                {
                    string responseStream = await response.Content.ReadAsStringAsync();

                    output = JsonConvert.DeserializeObject <ModelBaseStatus>(responseStream);
                }
            }

            return(output);
        }
Example #2
0
        public async Task <ModelBaseStatus> PostReferralCode([FromBody] PostReferralCode model)
        {
            var output       = new ModelBaseStatus();
            var checkRefCode = await _repoWrapper.AspNetUsers.FirstOrDefaultAsync(p => p.UserName == model.ReferralCode);

            if (checkRefCode == null)
            {
                output.ErrorCode = "01";
                output.Message   = $"Mã giới thiệu {model.ReferralCode} không tồn tại trên hệ thống. Mời bạn nhập lại và tiếp tục kiểm tra";
                return(output);
            }

            var checkCodeBrand = await _repoWrapper.Brand.FirstOrDefaultAsync(p => p.ProductBrand_ID == model.ProductBrandId);

            if (checkCodeBrand != null)
            {
                if (!String.IsNullOrEmpty(checkCodeBrand.ReferralCode))
                {
                    output.ErrorCode = "01";
                    output.Message   = $"Tài khoản đã được nhập mã giới thiệu";
                    return(output);
                }
            }

            var checkCodeCurrentUser = await _repoWrapper.AspNetUsers.FirstOrDefaultAsync(p => p.Id == model.UserId);

            if (checkCodeCurrentUser != null)
            {
                if (checkCodeCurrentUser.UserName == model.ReferralCode)
                {
                    output.ErrorCode = "01";
                    output.Message   = $"Không thể nhập mã giới thiệu của chính tài khoản hiện tại!";
                    return(output);
                }
            }
            var result = await _repoWrapper.Brand.UpdateBrandReferralCode(model.ProductBrandId, model.ReferralCode);

            if (result)
            {
                output.ErrorCode = "00";
                output.Message   = "Cập nhật thành công";
                return(output);
            }
            else
            {
                output.ErrorCode = "01";
                output.Message   = "Cập nhật thất bại";
                return(output);
            }
        }
Example #3
0
        public async Task <object> RefreshToken(string email)
        {
            var responseModel = new ModelBaseStatus();
            //Call refresh token
            var user = await _userManager.FindByNameAsync(email);

            if (user != null)
            {
                return(await RefreshToken(email, user));
            }
            else
            {
                responseModel.ErrorCode = "001";
                responseModel.Message   = "Không tồn tại account";
            }
            return(responseModel);
        }
Example #4
0
        public async Task <ModelBaseStatus> ActionInRec(int?Id, string Action)
        {
            ModelBaseStatus output = new ModelBaseStatus();
            var             jwt    = JsonConvert.DeserializeObject <SumProfileResponseDTO>(_httpContextAccessor.HttpContext.Request.Cookies["JWT"]);

            if (jwt != null)
            {
                _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwt.JWT);
                string apiUrl       = $"/api/v1/Recruitment/ActionInRec";
                string paramRequest = $"?Id={Id}&Action={Action}";
                var    response     = await _client.GetAsync(apiUrl + paramRequest);

                if (response.IsSuccessStatusCode)
                {
                    string responseStream = await response.Content.ReadAsStringAsync();

                    output = JsonConvert.DeserializeObject <ModelBaseStatus>(responseStream);
                }
            }

            return(output);
        }
Example #5
0
        public async Task <ModelBaseStatus> CheckRenewProduct()
        {
            ModelBaseStatus output = new ModelBaseStatus();
            var             jwt    = JsonConvert.DeserializeObject <SumProfileResponseDTO>(_httpContextAccessor.HttpContext.Request.Cookies["JWT"]);

            if (jwt != null)
            {
                _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwt.JWT);

                string apiUrl = $"/api/v1/Product/CheckRenew";
                apiUrl = apiUrl + $"?ProductBrandId={jwt.ProductBrandId}";
                var response = await _client.GetAsync(apiUrl);

                if (response.IsSuccessStatusCode)
                {
                    string responseStream = await response.Content.ReadAsStringAsync();

                    output = JsonConvert.DeserializeObject <ModelBaseStatus>(responseStream);
                }
            }

            return(output);
        }
Example #6
0
        //[Authorize]
        public async Task <ModelBaseStatus> PostShoppingCart(List <PostShoppingCart> model)
        {
            var output = new ModelBaseStatus();
            var result = await _repoWrapper.ShoppingCart.PostShopingCart(model);

            if (result.Count != 0)
            {
                output.ErrorCode = "00";
                output.Message   = "Đặt hàng thành công";
                foreach (var p in result)
                {
                    var product = await _repoWrapper.Product.FirstOrDefaultAsync(x => x.Product_ID == p.ProductId);

                    FCMMessageOutputDTO notiModel = new FCMMessageOutputDTO();
                    notiModel.Notification.Title = $"Đơn hàng được tạo mới";
                    notiModel.Notification.Body  = $"{DateTime.Now.ToString("dd/MM/yyyy")} Đơn hàng {p.ShopingCartCode} vừa được tạo mới";
                    notiModel.Topic             = product?.CreateBy.ToString(); // Thông báo tới gian hàng
                    notiModel.Data.formId       = "CART_BUY";
                    notiModel.Data.id           = p.Id;                         // ShoppingCartDetail ID
                    notiModel.Data.notiSpecType = 0;
                    var pushNoti = Utils.Util.SendMessageFirebase(notiModel);

                    FCMMessage fCMMessage = new FCMMessage();
                    fCMMessage.Title            = notiModel.Notification.Title;
                    fCMMessage.Body             = notiModel.Notification.Body;
                    fCMMessage.CreateBy         = product?.CreateBy;
                    fCMMessage.CreateDate       = DateTime.Now;
                    fCMMessage.LastEditBy       = product?.CreateBy;
                    fCMMessage.LastEditDate     = DateTime.Now;
                    fCMMessage.UserID           = product?.CreateBy;
                    fCMMessage.Topic            = product?.CreateBy.ToString(); // Thông báo tới gian hàng
                    fCMMessage.NotificationType = notiModel.Data.notifyType;
                    fCMMessage.Form_ID          = notiModel.Data.formId;
                    fCMMessage.ParameterId      = notiModel.Data.id;
                    fCMMessage.FullUrl          = notiModel.Data.fullUrl;
                    fCMMessage.FullUrlImage     = notiModel.Data.fullUrlImage;
                    fCMMessage.NotiSpecType     = 1;
                    fCMMessage.IsPinTop         = notiModel.Data.isPinTop;
                    fCMMessage.FormNameApp      = notiModel.Data.formAppName;
                    fCMMessage.ProductTypeId    = notiModel.Data.typeId;
                    fCMMessage.CategoryId       = notiModel.Data.categoryId;
                    fCMMessage.FullUrlImage     = $"https://hanoma-cdn.s3.cloud.cmctelecom.vn/DataMobile/Notify/notifyDefault.png";
                    fCMMessage.Content          = $"{DateTime.Now.ToString("dd/MM/yyyy")} Đơn hàng {p.ShopingCartCode} vừa được tạo mới";
                    fCMMessage.FullUrl          = "";


                    fCMMessage.HasRead = 0;
                    await _repoWrapper.FCMMessage.AddNewFCMMessage(fCMMessage);
                }
            }
            else
            {
                output.ErrorCode = "01";
                output.Message   = "Có lỗi trong quá trình đặt hàng";
                FCMMessageOutputDTO notiModel = new FCMMessageOutputDTO();
                notiModel.Notification.Title = "Có lỗi trong quá trình đặt hàng";
                notiModel.Notification.Body  = "Có lỗi trong quá trình đặt hàng";
                notiModel.Topic             = model[0].UserId; // Thông báo tới chính người dùng
                notiModel.Data.formId       = "SHOPPINGCARTNSS";
                notiModel.Data.notiSpecType = 0;
                var pushNoti = Utils.Util.SendMessageFirebase(notiModel);

                FCMMessage fCMMessage = new FCMMessage();
                fCMMessage.Title            = notiModel.Notification.Title;
                fCMMessage.Body             = notiModel.Notification.Body;
                fCMMessage.CreateBy         = Guid.Parse(model[0].UserId);
                fCMMessage.CreateDate       = DateTime.Now;
                fCMMessage.LastEditBy       = Guid.Parse(model[0].UserId);
                fCMMessage.LastEditDate     = DateTime.Now;
                fCMMessage.UserID           = Guid.Parse(model[0].UserId);
                fCMMessage.Topic            = model[0].UserId; // Thông báo tới chính người dùng
                fCMMessage.NotificationType = notiModel.Data.notifyType;
                fCMMessage.Form_ID          = notiModel.Data.formId;
                fCMMessage.ParameterId      = notiModel.Data.id;
                fCMMessage.FullUrl          = notiModel.Data.fullUrl;
                fCMMessage.FullUrlImage     = notiModel.Data.fullUrlImage;
                fCMMessage.NotiSpecType     = 1;
                fCMMessage.IsPinTop         = notiModel.Data.isPinTop;
                fCMMessage.FormNameApp      = notiModel.Data.formAppName;
                fCMMessage.ProductTypeId    = notiModel.Data.typeId;
                fCMMessage.CategoryId       = notiModel.Data.categoryId;
                fCMMessage.FullUrlImage     = $"https://hanoma-cdn.s3.cloud.cmctelecom.vn/DataMobile/Notify/notifyDefault.png";
                fCMMessage.Content          = "Có lỗi trong quá trình đặt hàng";
                fCMMessage.FullUrl          = "";


                fCMMessage.HasRead = 0;
                await _repoWrapper.FCMMessage.AddNewFCMMessage(fCMMessage);
            }
            return(output);
        }
Example #7
0
        public async Task <ModelBaseStatus> CheckRenew(int ProductBrandId)
        {
            var output = new ModelBaseStatus();

            return(output);
        }
Example #8
0
        public async Task <ModelBaseStatus> CheckPostProduct(int ProductBrandId)
        {
            var output = new ModelBaseStatus();

            if (ProductBrandId == 958) // set unlimited for product  brand
            {
                return(output);
            }
            var prodBrand = await _repoWrapper.Brand.FirstOrDefaultAsync(p => p.ProductBrand_ID == ProductBrandId);

            if (prodBrand != null)
            {
                if (prodBrand.ProductBrandType_ID == 1 || prodBrand.ProductBrandType_ID == null)
                {
                    var prodQty = await _repoPaymentWrapper.PaymentServcie.FirstOrDefaultAsync(p => p.ServiceId == 1);

                    var prodCount = await _repoWrapper.Product.CountProductByBrand(ProductBrandId);

                    if (prodCount >= prodQty.ProductQty)
                    {
                        output.ErrorCode = "01";
                        output.Message   = $"Bạn đã quá số tin đăng cho phép bạn cần hủy hoặc nâng cấp gian hàng lên quy mô cao hơn";
                        return(output);
                    }
                }
                if (prodBrand.ProductBrandType_ID == 2)
                {
                    var prodQty = await _repoPaymentWrapper.PaymentServcie.FirstOrDefaultAsync(p => p.ServiceId == 2);

                    var prodCount = await _repoWrapper.Product.CountProductByBrand(ProductBrandId);

                    if (prodCount >= prodQty.ProductQty)
                    {
                        output.ErrorCode = "01";
                        output.Message   = $"Bạn đã quá số tin đăng cho phép bạn cần hủy hoặc nâng cấp gian hàng lên quy mô cao hơn";
                        return(output);
                    }
                }
                if (prodBrand.ProductBrandType_ID == 3)
                {
                    var prodQty = await _repoPaymentWrapper.PaymentServcie.FirstOrDefaultAsync(p => p.ServiceId == 3);

                    var prodCount = await _repoWrapper.Product.CountProductByBrand(ProductBrandId);

                    if (prodCount >= prodQty.ProductQty)
                    {
                        output.ErrorCode = "01";
                        output.Message   = $"Bạn đã quá số tin đăng cho phép bạn cần hủy hoặc nâng cấp gian hàng lên quy mô cao hơn";
                        return(output);
                    }
                }
                else
                {
                    output.ErrorCode = "00";
                    output.Message   = "Được phép đăng tin";
                    return(output);
                }
            }
            else
            {
                output.ErrorCode = "01";
                output.Message   = $"Không tồn tại nhà cung cấp";
                return(output);
            }


            return(output);
        }