Beispiel #1
0
        public async Task <IActionResult> EditProductBrand([FromBody] PostProductBrandDTO model)
        {
            //logo
            if (model.ImgLogo != null)
            {
                String[] substrings = model.ImgLogo.Base64.Split(',');
                model.ImgLogo.Base64 = substrings[1];
            }


            //banner
            if (model.ImgBanner != null)
            {
                String[] substrings = model.ImgBanner.Base64.Split(',');
                model.ImgBanner.Base64 = substrings[1];
            }

            var result = await _repoWrapper.Profile.PutProductBrand(model);

            return(Json(result));
        }
Beispiel #2
0
        public async Task <object> DeleteProductBrand(string userId)
        {
            var output  = new PostProductBrandDTO();
            var pUserId = Guid.Parse(userId);

            try
            {
                var prodBrand = _repoWrapper.Brand.FirstOrDefault(p => p.CreateBy == pUserId);
                if (prodBrand == null)
                {
                    output.ErrorCode = "BRAND004";
                    output.Message   = Utils.ConstMessage.GetMsgConst("BRAND004");
                    return(output);
                }
                else
                {
                    var aspnetProfilers = _repoWrapper.AspNetUserProfiles.FirstOrDefaultAsync(p => p.UserId == userId);
                    if (aspnetProfilers != null)
                    {
                        try
                        {
                            _repoWrapper.AspNetUserProfiles.UpdateProductBrandToZero(userId);
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError($"DeleteProductBrand : {ex.ToString()}");
                            output.Message = "Có lỗi trong quá trình xóa";
                        }
                    }
                }
                output.ErrorCode = "00";
                output.Message   = "Xóa thành công";
            }
            catch (Exception ex)
            {
                _logger.LogError($"DeleteProductBrand: " + ex.ToString());
            }
            return(output);
        }
Beispiel #3
0
        public async Task <PostProductBrandDTO> PutProductBrand(PostProductBrandDTO postProductBrandDTO)
        {
            PostProductBrandDTO output = new PostProductBrandDTO();
            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/Brand/PutProductBrand";
                string paramRequest = $"?ProductBrandId={postProductBrandDTO.Data.ProductBrand_ID}";
                postProductBrandDTO.UserId = jwt.UserId;
                var json          = JsonConvert.SerializeObject(postProductBrandDTO, Formatting.Indented);
                var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
                var response      = await _client.PutAsync(apiUrl + paramRequest, stringContent);

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

                    output = JsonConvert.DeserializeObject <PostProductBrandDTO>(responseStream);
                }
            }
            return(output);
        }
Beispiel #4
0
        public async Task <PostProductBrandDTO> PutProductBrand(int ProductBrandId, PostProductBrandDTO model)
        {
            var output = new PostProductBrandDTO();

            output = model;
            var pUserId   = Guid.Parse(model.UserId);
            var prodBrand = _repoWrapper.Brand.FirstOrDefault(p => p.ProductBrand_ID == ProductBrandId && p.CreateBy == pUserId);

            if (prodBrand == null)
            {
                output.ErrorCode = "BRAND004";
                output.Message   = Utils.ConstMessage.GetMsgConst("BRAND004");
                return(output);
            }
            else
            {
                try
                {
                    if (!Util.IsEmail(model.Data.Email))
                    {
                        output.ErrorCode = "BRAND001";
                        output.Message   = Utils.ConstMessage.GetMsgConst("BRAND001");
                        return(output);
                    }
                    if (!Util.IsPhoneNumber(model.Data.Mobile?.Trim()))
                    {
                        output.ErrorCode = "BRAND002";
                        output.Message   = Utils.ConstMessage.GetMsgConst("BRAND002");
                        return(output);
                    }
                    if (String.IsNullOrEmpty(model.Data.Address))
                    {
                        output.ErrorCode = "BRAND005";
                        output.Message   = Utils.ConstMessage.GetMsgConst("BRAND005");
                        return(output);
                    }
                    var ProductBrandModel = _mapper.Map <ProductBrand>(model.Data);
                    ProductBrandModel.ProductBrand_ID = ProductBrandId;
                    var ProdBrandId = await _repoWrapper.Brand.PostProductBrand(ProductBrandModel, model.ImgLogo, model.ImgBanner, model.UserId);

                    if (ProdBrandId != 0)
                    {
                        // Save MainImage
                        if (!String.IsNullOrEmpty(model.ImgLogo.Base64))
                        {
                            SaveLogoImage(model.ImgLogo, ProdBrandId);
                        }
                        //Save Sub Image
                        if (!String.IsNullOrEmpty(model.ImgBanner.Base64))
                        {
                            SaveBannerImage(model.ImgBanner, ProdBrandId);
                        }

                        output.ErrorCode = "00";
                        output.Message   = "Cập nhật thành công";
                    }
                    else
                    {
                        output.ErrorCode = "001";
                        output.Message   = Utils.ConstMessage.GetMsgConst("001");
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError($"PutProductBrand: " + ex.ToString());
                }
            }
            return(output);
        }
Beispiel #5
0
        public async Task <PostProductBrandDTO> PostProductBrand(PostProductBrandDTO model)
        {
            _logger.LogDebug($"PostProductBrand: {JsonConvert.SerializeObject(model)}");
            var output = new PostProductBrandDTO();

            if (!Util.IsEmail(model.Data.Email))
            {
                output.ErrorCode = "BRAND001";
                output.Message   = Utils.ConstMessage.GetMsgConst("BRAND001");
                return(output);
            }
            if (!Util.IsPhoneNumber(model.Data.Mobile?.Trim()))
            {
                output.ErrorCode = "BRAND002";
                output.Message   = Utils.ConstMessage.GetMsgConst("BRAND002");
                return(output);
            }
            if (String.IsNullOrEmpty(model.Data.Address))
            {
                output.ErrorCode = "BRAND005";
                output.Message   = Utils.ConstMessage.GetMsgConst("BRAND005");
                return(output);
            }
            var UserProfilers = _repoWrapper.AspNetUserProfiles.FirstOrDefault(p => p.UserId == model.UserId);

            if (UserProfilers != null)
            {
                if (UserProfilers.ProductBrand_ID != null & UserProfilers.ProductBrand_ID > 0)
                {
                    output.ErrorCode = "BRAND003";
                    output.Message   = ConstMessage.GetMsgConst("BRAND003");
                    return(output);
                }
            }
            try
            {
                var ProductBrandModel = _mapper.Map <ProductBrand>(model.Data);
                var ProdBrandId       = await _repoWrapper.Brand.PostProductBrand(ProductBrandModel, model.ImgLogo, model.ImgBanner, model.UserId);

                if (ProdBrandId != 0)
                {
                    // Save MainImage
                    if (!String.IsNullOrEmpty(model.ImgLogo.Base64))
                    {
                        await SaveLogoImage(model.ImgLogo, ProdBrandId);
                    }
                    //Save Sub Image
                    if (!String.IsNullOrEmpty(model.ImgBanner.Base64))
                    {
                        await SaveBannerImage(model.ImgBanner, ProdBrandId);
                    }
                    output.Data.ProductBrand_ID = ProdBrandId;
                    ////Update Image
                    //_repoWrapper.Brand.UpdateImgProductBrand(ProductBrandModel, model.ImgLogo, model.ImgBanner, ProdBrandId, model.UserId);
                    _repoWrapper.FCMMessage.PushNotificationToRabitMQ(new NotificationRabitMQModel
                    {
                        Type             = "ONDEMAND",
                        NotificationCode = "DKCH",
                        ChannelSend      = "ALL",
                        UsingTemplate    = true,
                        UserId           = model.UserId,
                    });
                    output.ErrorCode = "00";
                    output.Message   = "Tạo gian hàng thành công";
                }
                else
                {
                    output.ErrorCode = "001";
                    output.Message   = Utils.ConstMessage.GetMsgConst("001");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"PostProductBrand: " + ex.ToString());
                output.ErrorCode = "001";
                output.Message   = Utils.ConstMessage.GetMsgConst("001");
            }
            return(output);
        }