Пример #1
0
        public int UpdateImgProductBrand(ProductBrand model, ImageUploadDTO imgLogo, ImageUploadDTO imgBanner, int ProductBrandId, string UserId)
        {
            var pUserId = Guid.Parse(UserId);

            if (model != null)
            {
                var prodBrandSave = HanomaContext.ProductBrand.Find(ProductBrandId);
                if (prodBrandSave != null)
                {
                    try
                    {
                        if (imgLogo.Base64 != null)
                        {
                            prodBrandSave.Logo = String.Format("{0}-mobile-logo.{1}", ProductBrandId, imgLogo.ExtensionType.Replace("image/", ""));
                        }

                        if (imgBanner.Base64 != null)
                        {
                            prodBrandSave.Banner = String.Format("{0}-mobile-banner.{1}", ProductBrandId, imgBanner.ExtensionType.Replace("image/", ""));
                        }

                        HanomaContext.SaveChanges();
                        return(model.ProductBrand_ID);
                    }
                    catch (Exception ex)
                    {
                        return(0);
                    }
                }
            }
            return(ProductBrandId);
        }
Пример #2
0
        public async Task <object> UpdateProductBrandToZero(string userId)
        {
            var pUserId = Guid.Parse(userId);

            try
            {
                var deleteProdBrand = await HanomaContext.ProductBrand.FirstOrDefaultAsync(p => p.CreateBy == pUserId);

                if (deleteProdBrand != null)
                {
                    HanomaContext.ProductBrand.RemoveRange(deleteProdBrand);
                    HanomaContext.SaveChanges();
                }
                var updateAspNetUserProfiles = await HanomaContext.AspNetUserProfiles.FirstOrDefaultAsync(p => p.UserId == userId);

                if (updateAspNetUserProfiles != null)
                {
                    updateAspNetUserProfiles.ProductBrand_ID = 0;
                    HanomaContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new object());
        }
Пример #3
0
        public async Task UpgradePackageBrand(int ProductBrandId, int ProductBrandTypeId)
        {
            var prodBrand = HanomaContext.ProductBrand.Find(ProductBrandId);

            if (prodBrand != null)
            {
                prodBrand.ProductBrandType_ID = ProductBrandTypeId;
                HanomaContext.SaveChanges();
            }
        }
Пример #4
0
        public async Task UpdateImgBannerProductBrand(string fileName, int ProductBrandId)
        {
            var prodBrand = HanomaContext.ProductBrand.Find(ProductBrandId);

            if (prodBrand != null)
            {
                prodBrand.Banner = fileName;
                HanomaContext.SaveChanges();
            }
        }
Пример #5
0
        public async Task UpdateImgLogoLibrary(string fileName, int LibraryId)
        {
            var lib = HanomaContext.Library.Find(LibraryId);

            if (lib != null)
            {
                lib.Image = fileName;
                HanomaContext.SaveChanges();
            }
        }
Пример #6
0
        public void CreateNewUserProfile(string userId, string Email, string Phone = null, int?accountType = 1)
        {
            try
            {
                var profileExist = HanomaContext.AspNetUserProfiles.FirstOrDefault(x => x.UserId.Equals(userId));
                if (profileExist != null)
                {
                    return;
                }


                var regtype = String.IsNullOrEmpty(Phone) ? "Email" : "Phone";
                if (regtype == "Email")
                {
                    //SendEmailToCEO(userId, Email);
                }
                else
                {
                    //SendEmailToCEO(userId, Phone);
                }

                var roles           = HanomaContext.AspNetRoles.ToList();
                var productBrand_ID = 0;

                HanomaContext.AspNetUserRoles.Add(new AspNetUserRoles()
                {
                    UserId = userId,
                    RoleId = roles.FirstOrDefault(x => x.Name.Equals("Thành viên")).Id
                });


                var profilers = new AspNetUserProfiles
                {
                    UserId = userId,
                    //FullName = Email,
                    Phone            = Phone,
                    AccountType      = 1, //accountType ?? 1,
                    ProductBrand_ID  = productBrand_ID,
                    RegType          = regtype,
                    RegisterDate     = DateTime.Now,
                    LastActivityDate = DateTime.Now,
                    Rank             = 1,
                    Location_ID      = -1
                };

                var profile = HanomaContext.AspNetUserProfiles.Add(profilers);
                HanomaContext.SaveChanges();
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
Пример #7
0
 public void UpdateUserProfiler(string userId, int productBrandId)
 {
     try
     {
         var profiler = HanomaContext.AspNetUserProfiles.FirstOrDefault(x => x.UserId.Equals(userId));
         profiler.ProductBrand_ID = productBrandId;
         HanomaContext.SaveChanges();
     }
     catch (Exception exception)
     {
         //   log.Error(exception);
     }
 }
Пример #8
0
        public void UpdateFCMClient(Guid fcmClientId, FCMClient fcmClient)
        {
            var fcmClientItem = HanomaContext.FCMClient.Find(fcmClientId);

            if (fcmClientItem != null)
            {
                fcmClientItem.LastSeen = DateTime.Now;
                fcmClientItem.UserID   = fcmClient.UserID;
                fcmClientItem.UserName = fcmClient.UserName;
                fcmClientItem.Topic    = fcmClient.UserID.ToString();
                HanomaContext.SaveChanges();
            }
        }
Пример #9
0
 public void UpdateUrlProductBrand(int productBrandId)
 {
     try
     {
         var productBrand = HanomaContext.ProductBrand.FirstOrDefault(x => x.ProductBrand_ID == productBrandId);
         var urlNew       = FormatURL(productBrand.Name) + "-" + productBrand.ProductBrand_ID.ToString();
         productBrand.URL = urlNew;
         HanomaContext.SaveChanges();
     }
     catch (Exception exception)
     {
         //log.Error(exception);
     }
 }
Пример #10
0
 public void UpdateUrl(int libraryId)
 {
     try
     {
         var lib    = HanomaContext.Library.FirstOrDefault(x => x.Library_ID == libraryId);
         var urlNew = FormatURL(lib.Title) + "-" + lib.Library_ID.ToString();
         lib.URL = urlNew;
         HanomaContext.SaveChanges();
     }
     catch (Exception exception)
     {
         //log.Error(exception);
     }
 }
Пример #11
0
        public void UpgradeAccountAfterRegister(string userId)
        {
            try
            {
                var profilers    = HanomaContext.AspNetUserProfiles.FirstOrDefault(x => x.UserId.Equals(userId));
                var productBrand = HanomaContext.ProductBrand.FirstOrDefault(x => x.ProductBrand_ID == profilers.ProductBrand_ID);
                profilers.AccountType = 2;

                HanomaContext.AspNetUserRoles.Add(new AspNetUserRoles
                {
                    UserId = userId,
                    RoleId = HanomaContext.AspNetRoles.FirstOrDefault(x => x.Name.Equals("Tài khoản Doanh nghiệp")).Id
                });
                HanomaContext.SaveChanges();
            }
            catch (Exception exception)
            {
                //log.Error(exception);
            }
        }
Пример #12
0
 public void UpdateProductBrandIdOfProduct(string userId, int productBrandId)
 {
     try
     {
         var userIdGuid = new Guid(userId);
         var products   = HanomaContext.Product.Where(x => x.CreateBy == userIdGuid).ToList();
         if (products == null || products.Count < 1)
         {
             return;
         }
         foreach (var product in products)
         {
             product.ProductBrand_ID = productBrandId;
             HanomaContext.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         //   log.Error(ex);
     }
 }
Пример #13
0
 public async Task <ProductModel> PostProductModel(ProductModel model, string UserId)
 {
     try
     {
         var pUser = Guid.Parse(UserId);
         model.Name         = model.Name.ToUpper();
         model.CreateBy     = pUser;
         model.LastEditBy   = pUser;
         model.CreateDate   = DateTime.Now;
         model.LastEditDate = DateTime.Now;
         model.IsEnable     = true;
         model.StatusType   = 1; // mới thêm
         HanomaContext.ProductModel.Add(model);
         HanomaContext.SaveChanges();
     }
     catch (Exception ex)
     {
         model.ProductModel_ID = 0;
         throw ex;
     }
     return(model);
 }
Пример #14
0
        public async Task <int> UpdateHasRead(string UserId, int HasRead, int?FCMMessageID = 0, int?NotiSpecType = 0)
        {
            try
            {
                if (FCMMessageID != 0)
                {
                    var fcmMessage = HanomaContext.FCMMessage.FirstOrDefault(p => p.FCMMessage_ID == FCMMessageID && p.Topic == UserId);
                    if (fcmMessage != null)
                    {
                        fcmMessage.HasRead = HasRead;
                        HanomaContext.SaveChanges();
                    }
                }
                else
                {
                    if (NotiSpecType == 0)
                    {
                        var lstFcmMessage = HanomaContext.FCMMessage.Where(p => p.Topic == UserId);
                        await lstFcmMessage.ForEachAsync(p => p.HasRead = HasRead);

                        HanomaContext.SaveChanges();
                    }
                    else
                    {
                        var lstFcmMessage = HanomaContext.FCMMessage.Where(p => p.Topic == UserId && p.NotiSpecType == NotiSpecType);
                        await lstFcmMessage.ForEachAsync(p => p.HasRead = HasRead);

                        HanomaContext.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                return(0);
            }
            return(1);
        }
Пример #15
0
        public async Task <object> Register([FromBody] RegisterDto model)
        {
            var reponseModel = new RegisterDto();

            reponseModel.Email = model.Email;
            var InputEmail = model.Email;
            var code       = "";

            if (Util.IsPhoneNumber(model.Email))
            {
                InputEmail = $"{model.Email}@hanoma.vn";
            }
            //Check input Email Pass
            if (String.IsNullOrEmpty(model.Email) || String.IsNullOrEmpty(model.Password))
            {
                reponseModel.ErrorCode = "ACC006";
                reponseModel.Message   = ConstMessage.GetMsgConst("ACC006");
                return(reponseModel);
            }
            //Check exists User with not confirm
            if (_repositoryWrapper.AspNetUsers.CheckExistsUserNotConfirmed(model.Email))
            {
                //reponseModel.ErrorCode = "ACC013";
                //reponseModel.Message = ConstMessage.GetMsgConst("ACC013");
                //SentCode if not confirm

                var user = new ApplicationUser
                {
                    UserName = model.Email,
                    Email    = InputEmail
                };
                //if (!Util.IsPhoneNumber(model.Email))
                //{

                //    code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, model.Email);
                //}
                //else
                //{
                //    code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, model.Email);
                //}
                //await SendCode(Util.IsPhoneNumber(model.Email) ? "Phone" : "Email", model.Email, code);
                reponseModel.ErrorCode = "00";
                reponseModel.Message   = "Đã gửi code xác nhận";
                return(reponseModel);
            }
            //Check exists User
            if (_repositoryWrapper.AspNetUsers.CheckExistsUser(model.Email))
            {
                reponseModel.ErrorCode = "ACC009";
                reponseModel.Message   = ConstMessage.GetMsgConst("ACC009");
                return(reponseModel);
            }

            if (!Util.IsEmailOrPhone(model.Email))
            {
                _logger.LogError($"[AccountController] {model.Email}" + ConstMessage.GetMsgConst("ACC010"));
                reponseModel.ErrorCode = "ACC010";
                reponseModel.Message   = ConstMessage.GetMsgConst("ACC010");
                return(reponseModel);
            }
            else
            {
                var user = new ApplicationUser
                {
                    UserName = model.Email,
                    Email    = InputEmail
                };

                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    //Set EnableTwoFactorAuthentication
                    //await _userManager.SetTwoFactorEnabledAsync(user, true);

                    //Update Account Code
                    var userRegister = _repositoryWrapper.AspNetUsers.FirstOrDefault(x => x.Id.Equals(user.Id));
                    userRegister.AccountCode = $"84{model.Email}";
                    _hanomaContext.SaveChanges();



                    _logger.LogInfo($"[AccountController] Đăng ký thành công {model.Email} ");
                    try
                    {
                        //Create User Profile
                        _repositoryWrapper.AspNetUsers.CreateNewUserProfile(user.Id, user.Email, null, 1);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"[Account Controller] {ex}");
                    }
                    if (!Util.IsPhoneNumber(model.Email))
                    {
                        code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, model.Email);
                    }
                    else
                    {
                        code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, model.Email);
                    }

                    //Thay đổi luồng verify số điện thoại trước
                    //await SendCode(Util.IsPhoneNumber(model.Email) ? "Phone" : "Email", model.Email, code);
                    reponseModel.Email     = model.Email;
                    reponseModel.Password  = model.Password;
                    reponseModel.ErrorCode = "00";
                    reponseModel.Message   = "Đăng ký thành công";
                    return(reponseModel);
                }
            }

            throw new ApplicationException("UNKNOWN_ERROR");
        }
Пример #16
0
 public void Save()
 {
     _hanomaContext.SaveChanges();
 }