Beispiel #1
0
        private async Task <IActionResult> PutSetting(int id, Setting setting)
        {
            if (id != setting.Setting_ID)
            {
                return(BadRequest());
            }

            _context.Entry(setting).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SettingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
        public async Task AddNewFCMMessage(FCMMessage model)
        {
            FCMMessage item = new FCMMessage();

            item = model;
            HanomaContext.Add(item);
            await HanomaContext.SaveChangesAsync();
        }
Beispiel #3
0
        public Task UpdateData(FCMMessage Content)
        {
            //FCMMessage CurrentFCMMessage = HanomaContext.FCMMessage.FirstOrDefault(p => p.FCMMessage_ID == FCMMessage_ID);
            FCMMessage CurrentFCMMessage = new FCMMessage();

            CurrentFCMMessage.Title            = Content.Title;
            CurrentFCMMessage.Body             = Content.Body;
            CurrentFCMMessage.Content          = Content.Content;
            CurrentFCMMessage.UserName         = "";
            CurrentFCMMessage.UserID           = Content.UserID;
            CurrentFCMMessage.NotificationType = Content.NotificationType;
            CurrentFCMMessage.Form_ID          = Content.Form_ID;
            CurrentFCMMessage.ParameterId      = Content.ParameterId ?? 0;
            CurrentFCMMessage.FullUrl          = Content.FullUrl;
            CurrentFCMMessage.Topic            = Content.Topic;
            CurrentFCMMessage.CreateDate       = DateTime.Now;
            CurrentFCMMessage.CreateBy         = Content.UserID;
            CurrentFCMMessage.UserID           = Content.UserID;
            HanomaContext.FCMMessage.Add(CurrentFCMMessage);
            HanomaContext.SaveChangesAsync();


            //Insert FCMMessageToken
            //if (Content.Topic == "Global")
            //{
            //    var ItemClient = HanomaContext.FCMClient.Select(p => p.UserID).Distinct().ToList();
            //    foreach (var p in ItemClient)
            //    {
            //        FCMMessageForTokken item = new FCMMessageForTokken();
            //        if (p != null) item.UserID = p.Value;
            //        item.FCMMessage_ID = CurrentFCMMessage.FCMMessage_ID;
            //        item.CreateBy = Guid.Parse(User_ID);
            //        item.CreateDate = DateTime.Now;
            //        HanomaContext.FCMMessageForTokken.Add(item);
            //        HanomaContext.SaveChangesAsync();
            //    }
            //}
            //else
            //{
            //    var ItemClient = HanomaContext.FCMClient.Where(p => p.Topic == Content.Topic).Select(i => i.UserID).Distinct().ToList();
            //    if (ItemClient != null)
            //    {
            //        foreach (var p in ItemClient)
            //        {
            //            FCMMessageForTokken item = new FCMMessageForTokken();
            //            if (p != null) item.UserID = p.Value;
            //            item.FCMMessage_ID = CurrentFCMMessage.FCMMessage_ID;
            //            item.CreateBy = Guid.Parse(User_ID);
            //            item.CreateDate = DateTime.Now;
            //            HanomaContext.FCMMessageForTokken.Add(item);
            //            HanomaContext.SaveChangesAsync();
            //        }
            //    }
            //}

            return(Task.CompletedTask);
        }
Beispiel #4
0
        public int AddNewData(string UserID)
        {
            FCMMessage CurrentFCMMessage = new FCMMessage();

            CurrentFCMMessage.CreateDate = DateTime.Now;
            CurrentFCMMessage.CreateBy   = Guid.Parse(UserID);
            HanomaContext.FCMMessage.Add(CurrentFCMMessage);
            HanomaContext.SaveChangesAsync();
            return(CurrentFCMMessage.FCMMessage_ID);
        }
Beispiel #5
0
        public void CreateUserSocial(string LoginProvider, string ProviderKey, string UserId)
        {
            var checkExist = HanomaContext.AspNetUserLogins.FirstOrDefault(p =>
                                                                           p.LoginProvider == LoginProvider && p.ProviderKey == ProviderKey);

            if (checkExist == null)
            {
                AspNetUserLogins item = new AspNetUserLogins();
                item.LoginProvider = LoginProvider;
                item.ProviderKey   = ProviderKey;
                item.UserId        = UserId;
                HanomaContext.AspNetUserLogins.Add(item);
                HanomaContext.SaveChangesAsync();
            }
        }
Beispiel #6
0
        public async Task <bool> UpdateBrandReferralCode(int ProductBrandId, string ReferralCode)
        {
            var prodBrand = HanomaContext.ProductBrand.Find(ProductBrandId);

            if (prodBrand != null)
            {
                prodBrand.ReferralCode     = ReferralCode;
                prodBrand.ReferralCodeDate = DateTime.Now;
                HanomaContext.SaveChangesAsync();
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public async Task <bool> DeleteDeliveryAddress(int Id, string UserId)
        {
            var pUserId = Guid.Parse(UserId);
            var item    = await HanomaContext.DeliveryAddress.FirstOrDefaultAsync(p => p.CreateBy == pUserId && p.Id == Id);

            if (item == null)
            {
                return(false);
            }
            else
            {
                HanomaContext.DeliveryAddress.Remove(item);
                await HanomaContext.SaveChangesAsync();

                return(true);
            }
        }
        public async Task <int> SubscriptionEmail(string email)
        {
            var result       = new Subscription();
            var subscription = await HanomaContext.Subscription.FirstOrDefaultAsync(x => x.Email.Equals(email));

            var model = new Subscription
            {
                Email      = email,
                CreateDate = DateTime.Now,
                Active     = true
            };
            await HanomaContext.Subscription.AddAsync(model);

            await HanomaContext.SaveChangesAsync();

            return(model.Subscription_ID);
        }
        public async Task <bool> PostShopingCartAction(ShoppingCartDetailDTO model)
        {
            var item = HanomaContext.ShoppingCartDetail.Find(model.Id);

            if (item != null)
            {
                item.StatusCart      = model.StatusCart;
                item.ReasonCancel    = model.ReasonCancel; // Lý do hủy
                item.IsCancelByBuyer = model.IsCancelByBuyer;
                item.LastEditBy      = Guid.Parse(model.UserId);
                item.LastEditDate    = DateTime.Now;
                await HanomaContext.SaveChangesAsync();
            }
            else
            {
                return(false);
            }
            return(true);
        }
Beispiel #10
0
        public async Task <bool> PostContactAds(ContactAdsDTO model)
        {
            try
            {
                var modelContact = new ContactAds();
                modelContact.Name         = model.Name;
                modelContact.Address      = model.Address;
                modelContact.Content      = model.Content;
                modelContact.Mobile       = model.Mobile;
                modelContact.Email        = model.Email;
                modelContact.CreateDate   = DateTime.Now;
                modelContact.LastEditDate = DateTime.Now;
                modelContact.Status       = 1;

                HanomaContext.ContactAds.Add(modelContact);
                await HanomaContext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
        public async Task <List <ShoppingCartDetail> > PostShopingCart(List <PostShoppingCart> model)
        {
            var output = new List <ShoppingCartDetail>();

            try
            {
                if (model != null)
                {
                    foreach (var item in model)
                    {
                        ShoppingCartMaster itemMaster = new ShoppingCartMaster();
                        itemMaster.UserId          = Guid.Parse(item.UserId);
                        itemMaster.ProductBrandId  = item.ProductBrandID;
                        itemMaster.DeliveryAddress = item.DeliveryAddress;
                        itemMaster.TotalAmount     = item.TotalAmmout;
                        itemMaster.CreateBy        = Guid.Parse(item.UserId);
                        itemMaster.CreateDate      = DateTime.Now;
                        itemMaster.LastEditBy      = Guid.Parse(item.UserId);
                        itemMaster.LastEditDate    = DateTime.Now;
                        HanomaContext.ShoppingCartMaster.Add(itemMaster);
                        await HanomaContext.SaveChangesAsync();


                        foreach (var p in item.LstShopCartDetail)
                        {
                            var lastId = await HanomaContext.ShoppingCartDetail.OrderByDescending(p => p.Id).FirstOrDefaultAsync();

                            ShoppingCartDetail itemDetail = new ShoppingCartDetail();
                            itemDetail.ShoppingCartMasterId = itemMaster.Id;
                            itemDetail.ShopingCartCode      = "HNM" + String.Format("{0:D7}", lastId == null ? 1 : lastId.Id + 1);
                            itemDetail.ProductId            = p.ProductId;
                            var itemProduct = await HanomaContext.Product.FindAsync(p.ProductId);

                            if (itemProduct != null) // Get price from server
                            {
                                itemDetail.Price = p.Price;
                            }
                            itemDetail.Qty          = p.Qty;
                            itemDetail.DisCount     = p.Discount;
                            itemDetail.Remark       = p.Remark;
                            itemDetail.StatusCart   = 1; // Waiting confirm
                            itemDetail.CreateBy     = Guid.Parse(item.UserId);
                            itemDetail.CreateDate   = DateTime.Now;
                            itemDetail.LastEditBy   = Guid.Parse(item.UserId);
                            itemDetail.LastEditDate = DateTime.Now;
                            HanomaContext.ShoppingCartDetail.Add(itemDetail);
                            await HanomaContext.SaveChangesAsync();

                            //
                            output.Add(itemDetail);
                        }
                    }
                }
                else
                {
                    return(output);
                }
            }
            catch (Exception ex)
            {
                return(output);
            }
            return(output);
        }
        public async Task <bool> PostDeliveryAddress(DeliveryAddressDTO model)
        {
            try
            {
                if (model != null)
                {
                    var pUserId = Guid.Parse(model.UserId);
                    var item    = await HanomaContext.DeliveryAddress.FirstOrDefaultAsync(p => p.Id == model.Id && p.CreateBy == pUserId);

                    if (item == null)
                    {
                        //Add Delivery
                        var addItem = new DeliveryAddress();
                        addItem.UserId       = pUserId;
                        addItem.UserName     = model.UserName;
                        addItem.PhoneNumber  = model.PhoneNumber;
                        addItem.LocationId   = model.LocationId;
                        addItem.DistrictId   = model.DistrictId;
                        addItem.Address      = model.Address;
                        addItem.IsDefault    = model.IsDefault;
                        addItem.CreateBy     = pUserId;
                        addItem.CreateDate   = DateTime.Now;
                        addItem.LastEditBy   = pUserId;
                        addItem.LastEditDate = DateTime.Now;
                        HanomaContext.DeliveryAddress.Add(addItem);
                        await HanomaContext.SaveChangesAsync();

                        //Update Default
                        if (model.IsDefault == true)
                        {
                            var lstItem = await HanomaContext.DeliveryAddress.Where(p => p.CreateBy == pUserId).ToListAsync();

                            foreach (var p in lstItem)
                            {
                                if (p.Id == addItem.Id)
                                {
                                    continue;
                                }
                                var pItem = await HanomaContext.DeliveryAddress.FirstOrDefaultAsync(x => x.Id == p.Id);

                                pItem.IsDefault = false;
                                await HanomaContext.SaveChangesAsync();
                            }
                        }
                    }
                    else
                    {
                        //Update
                        item.UserName     = model.UserName;
                        item.PhoneNumber  = model.PhoneNumber;
                        item.LocationId   = model.LocationId;
                        item.DistrictId   = model.DistrictId;
                        item.Address      = model.Address;
                        item.IsDefault    = model.IsDefault;
                        item.LastEditBy   = pUserId;
                        item.LastEditDate = DateTime.Now;
                        await HanomaContext.SaveChangesAsync();

                        //Update Default
                        if (model.IsDefault == true)
                        {
                            var lstItem = await HanomaContext.DeliveryAddress.Where(p => p.CreateBy == pUserId).ToListAsync();

                            foreach (var p in lstItem)
                            {
                                if (p.Id == model.Id)
                                {
                                    continue;
                                }
                                var pItem = await HanomaContext.DeliveryAddress.FirstOrDefaultAsync(x => x.Id == p.Id);

                                pItem.IsDefault = false;
                                await HanomaContext.SaveChangesAsync();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
Beispiel #13
0
        public async Task <int> PostProductBrand(ProductBrand model, ImageUploadDTO imgLogo, ImageUploadDTO imgBanner, string UserId)
        {
            var pUserId = Guid.Parse(UserId);

            if (model != null)
            {
                var prodBrandSave = HanomaContext.ProductBrand.Find(model.ProductBrand_ID);
                if (prodBrandSave == null)
                {
                    var productBrandNew = new ProductBrand
                    {
                        Location_ID         = model.Location_ID,
                        Name                = model.Name,
                        TradingName         = model.TradingName,
                        BrandName           = model.BrandName,
                        BusinessArea        = model.BusinessArea,
                        Address             = model.Address,
                        Telephone           = model.Telephone,
                        Mobile              = model.Mobile,
                        Website             = model.Website,
                        Description         = model.Description,
                        Email               = model.Email,
                        LastEditDate        = DateTime.Now,
                        CreateDate          = DateTime.Now,
                        Verified            = true,
                        Active              = true,
                        URL                 = null,
                        CreateBy            = new Guid(UserId),
                        LastEditBy          = new Guid(UserId),
                        District            = model.District,
                        PostalCode          = model.PostalCode,
                        Country_ID          = model.Country_ID,
                        EmailDisplay        = model.EmailDisplay,
                        MapCode             = model.MapCode,
                        ReferralCode        = model.ReferralCode,
                        ProductBrandType_ID = 1 // Gian hàng quy mô nhỏ
                    };
                    try
                    {
                        HanomaContext.ProductBrand.Add(productBrandNew);
                        await HanomaContext.SaveChangesAsync();

                        UpdateUrlProductBrand(productBrandNew.ProductBrand_ID);
                        UpdateProductBrandIdOfProduct(UserId, productBrandNew.ProductBrand_ID);
                        UpgradeAccountAfterRegister(UserId);
                        UpdateUserProfiler(UserId, productBrandNew.ProductBrand_ID);
                        return(productBrandNew.ProductBrand_ID);
                    }
                    catch (Exception ex)
                    {
                        productBrandNew.ProductBrand_ID = 0;
                        return(productBrandNew.ProductBrand_ID);
                    }
                }
                else
                {
                    try
                    {
                        var urlNew = FormatURL(model.Name) + "-" + model.ProductBrand_ID.ToString();

                        prodBrandSave.Location_ID  = model.Location_ID;
                        prodBrandSave.Name         = model.Name;
                        prodBrandSave.TradingName  = model.TradingName;
                        prodBrandSave.BrandName    = model.BrandName;
                        prodBrandSave.BusinessArea = model.BusinessArea;
                        prodBrandSave.Address      = model.Address;
                        prodBrandSave.Telephone    = model.Telephone;
                        prodBrandSave.Mobile       = model.Mobile;
                        prodBrandSave.Website      = model.Website;
                        prodBrandSave.Description  = model.Description;
                        prodBrandSave.Email        = model.Email;
                        prodBrandSave.LastEditDate = DateTime.Now;
                        prodBrandSave.Verified     = true;
                        prodBrandSave.Active       = true;
                        prodBrandSave.URL          = urlNew;
                        prodBrandSave.LastEditBy   = pUserId;
                        prodBrandSave.District     = model.District;
                        prodBrandSave.PostalCode   = model.PostalCode;
                        prodBrandSave.Country_ID   = model.Country_ID;
                        prodBrandSave.EmailDisplay = model.EmailDisplay;
                        prodBrandSave.MapCode      = model.MapCode;
                        prodBrandSave.ReferralCode = model.ReferralCode;
                        await HanomaContext.SaveChangesAsync();

                        UpdateUserProfiler(UserId, model.ProductBrand_ID);

                        return(model.ProductBrand_ID);
                    }
                    catch (Exception ex)
                    {
                        return(0);
                    }
                }
            }
            return(model.ProductBrand_ID);
        }
Beispiel #14
0
 public async Task Log(LogAPI apiLogItem)
 {
     _db.LogAPI.Add(apiLogItem);
     await _db.SaveChangesAsync();
 }
Beispiel #15
0
 public Task <int> SaveChangesAsync()
 {
     return(_hanomaContext.SaveChangesAsync());
 }
Beispiel #16
0
        public async Task <int> PostLibrary(Library model, ImageUploadDTO imgLogo, string UserId)
        {
            var pUserId = Guid.Parse(UserId);

            if (model != null)
            {
                var libSave = HanomaContext.Library.Find(model.Library_ID);
                if (libSave == null)
                {
                    var libraryNew = new Library
                    {
                        LibraryCategory_ID = model.LibraryCategory_ID,
                        LibraryType_ID     = model.LibraryType_ID,
                        Title             = model.Title,
                        SubTitle          = model.SubTitle,
                        Image             = model.Image,
                        Description       = model.Description,
                        Content           = model.Content,
                        Author            = model.Author,
                        CreateDate        = DateTime.Now,
                        Counter           = model.Counter,
                        Active            = true,
                        URL               = null,
                        CreateBy          = new Guid(UserId),
                        LastEditBy        = new Guid(UserId),
                        LastEditDate      = model.LastEditDate,
                        Tag               = model.Tag,
                        Keyword           = model.Keyword,
                        AllowComment      = model.AllowComment,
                        MetaTitle         = model.MetaTitle,
                        MetaDescription   = model.MetaDescription,
                        AuthorPhone       = model.AuthorPhone,
                        MetaKeywords      = model.MetaKeywords,
                        AuthorEmail       = model.AuthorEmail,
                        AuthorJob         = model.AuthorJob,
                        AuthorCompany     = model.AuthorCompany,
                        ProductCategoryID = model.ProductCategoryID,
                        ManufactoryID     = model.ManufactoryID,
                        ModelID           = model.ModelID,
                        StatusType_ID     = 2,
                    };
                    try
                    {
                        HanomaContext.Library.Add(libraryNew);
                        await HanomaContext.SaveChangesAsync();

                        UpdateUrl(libraryNew.Library_ID);
                        return(libraryNew.Library_ID);
                    }
                    catch (Exception ex)
                    {
                        libraryNew.Library_ID = 0;
                        return(libraryNew.Library_ID);
                    }
                }
                else
                {
                    try
                    {
                        var urlNew = FormatURL(model.Title) + "-" + model.Library_ID.ToString();

                        libSave.LibraryCategory_ID = model.LibraryCategory_ID;
                        libSave.LibraryType_ID     = model.LibraryType_ID;
                        libSave.Title             = model.Title;
                        libSave.SubTitle          = model.SubTitle;
                        libSave.Image             = model.Image;
                        libSave.Description       = model.Description;
                        libSave.Content           = model.Content;
                        libSave.Author            = model.Author;
                        libSave.CreateDate        = DateTime.Now;
                        libSave.Counter           = model.Counter;
                        libSave.Active            = true;
                        libSave.URL               = null;
                        libSave.CreateBy          = new Guid(UserId);
                        libSave.LastEditBy        = new Guid(UserId);
                        libSave.LastEditDate      = model.LastEditDate;
                        libSave.Tag               = model.Tag;
                        libSave.Keyword           = model.Keyword;
                        libSave.AllowComment      = model.AllowComment;
                        libSave.MetaTitle         = model.MetaTitle;
                        libSave.MetaDescription   = model.MetaDescription;
                        libSave.AuthorPhone       = model.AuthorPhone;
                        libSave.MetaKeywords      = model.MetaKeywords;
                        libSave.AuthorEmail       = model.AuthorEmail;
                        libSave.AuthorJob         = model.AuthorJob;
                        libSave.AuthorCompany     = model.AuthorCompany;
                        libSave.ProductCategoryID = model.ProductCategoryID;
                        libSave.ManufactoryID     = model.ManufactoryID;
                        libSave.ModelID           = model.ModelID;
                        libSave.StatusType_ID     = -1;
                        await HanomaContext.SaveChangesAsync();

                        return(model.Library_ID);
                    }
                    catch (Exception ex)
                    {
                        return(0);
                    }
                }
            }
            return(model.Library_ID);
        }