Esempio n. 1
0
        private static Boolean saveInDb(PistisContext db, Message msg)
        {
            var model = new VendorChat();

            model.CustomerId             = msg.CustomerId;
            model.IsActive               = true;
            model.ProductVariantDetailId = msg.ProductVariantDetailId;
            model.VendorId               = msg.VendorId;
            model.IpAddress              = msg.IpAddress;
            model.IsArchieved            = false;
            model.ProductVariantDetailId = msg.ProductVariantDetailId;
            db.VendorChat.Add(model);
            try
            {
                db.SaveChanges();
                var data = new VendorChatMsg();
                data.CustomerMsg    = msg.CustomerMsg;
                data.DateTime       = DateTime.Now;
                data.IsCustomerRead = false;
                data.IsVendorRead   = false;
                data.VendorChatId   = model.Id;
                data.VendorMsg      = msg.VendorMsg;
                db.VendorChatMsg.Add(data);
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> getOldMsgs(getOldMsgModel model)
        {
            var result = new List <OldMessage>();
            var data   = new VendorChat();
            var data1  = db.VendorChat.Where(x => x.ProductVariantDetailId == model.ProductVariantDetailId && x.IsArchieved == false).ToList();

            if (model.CustomerId != 0)
            {
                data = data1.Where(x => x.CustomerId == model.CustomerId).FirstOrDefault();
            }
            if (model.VendorId != 0)
            {
                data = data1.Where(x => x.VendorId == model.VendorId).FirstOrDefault();
            }

            if (data != null)
            {
                var customer = await db.Users.Where(x => x.Id == data.CustomerId).FirstOrDefaultAsync();

                var vendor = await db.Users.Where(x => x.Id == data.VendorId).FirstOrDefaultAsync();

                var productdetail = await db.ProductVariantDetails.Where(x => x.Id == data.ProductVariantDetailId).Include(x => x.Product.ProductImages).FirstOrDefaultAsync();

                var msg = await db.VendorChatMsg.Where(x => x.VendorChatId == data.Id).Include(x => x.VendorChat).ToListAsync();

                foreach (var m in msg)
                {
                    var r = new OldMessage();
                    r.CustomerId             = data.CustomerId;
                    r.VendorId               = data.VendorId;
                    r.CustomerMsg            = m.CustomerMsg;
                    r.VendorMsg              = m.VendorMsg;
                    r.Date                   = m.DateTime;
                    r.Id                     = m.Id;
                    r.IpAddress              = data.IpAddress;
                    r.ProductVariantDetailId = data.ProductVariantDetailId;
                    r.CustomerName           = customer.FirstName + " " + customer.LastName;
                    r.VendorName             = vendor.DisplayName;
                    r.ProductName            = productdetail.Product.Name;
                    r.ProductImage           = productdetail.Product.ProductImages.Where(x => x.IsActive == true && x.IsDefault == true).FirstOrDefault() == null?productdetail.Product.ProductImages.Where(x => x.IsActive == true).FirstOrDefault().ImagePath150x150 : productdetail.Product.ProductImages.Where(x => x.IsActive == true && x.IsDefault == true).FirstOrDefault().ImagePath150x150;

                    result.Add(r);
                }

                var IsRead = ReadMsg(msg, model.VendorId);
                var noti   = readnotification(model.VendorId, model.CustomerId, model.ProductId, model.ProductVariantDetailId);
            }
            return(Ok(result));
        }
Esempio n. 3
0
        public Boolean saveInDb(Message msg)
        {
            var model    = new VendorChat();
            var vendorid = 0;

            if (msg.VendorId == 0)
            {
                vendorid = db.Products.Where(x => x.Id == msg.ProductId).FirstOrDefault().VendorId;
            }
            else
            {
                vendorid = msg.VendorId;
            }
            model = db.VendorChat.Where(x => x.IsActive == true && x.IsArchieved == false && x.VendorId == vendorid && x.ProductVariantDetailId == msg.ProductVariantDetailId && x.CustomerId == msg.CustomerId).FirstOrDefault();
            if (model == null)
            {
                model                        = new VendorChat();
                model.CustomerId             = msg.CustomerId;
                model.IsActive               = true;
                model.ProductVariantDetailId = msg.ProductVariantDetailId;

                model.IpAddress              = msg.IpAddress;
                model.VendorId               = vendorid;
                model.IsArchieved            = false;
                model.ProductVariantDetailId = msg.ProductVariantDetailId;
                db.VendorChat.Add(model);
            }
            try
            {
                db.SaveChanges();
                var data = new VendorChatMsg();
                data.CustomerMsg    = msg.CustomerMsg;
                data.DateTime       = DateTime.Now;
                data.IsCustomerRead = false;
                data.IsVendorRead   = false;
                data.VendorChatId   = model.Id;
                data.VendorMsg      = msg.VendorMsg;
                db.VendorChatMsg.Add(data);
                db.SaveChanges();
                var chat = new AllChats();
                chat.CustomerId = model.CustomerId;
                var cust = db.Users.Where(x => x.Id == model.CustomerId).FirstOrDefault();
                chat.CustomerName = cust.FirstName + " " + cust.LastName;
                var vendor = db.Users.Where(x => x.Id == model.VendorId).FirstOrDefault();
                chat.VendorName             = vendor.DisplayName;
                chat.Date                   = data.DateTime;
                chat.LastMsg                = data.CustomerMsg;
                chat.ProductId              = msg.ProductId;
                chat.ProductVariantDetailId = model.ProductVariantDetailId;
                chat.VendorId               = model.VendorId;
                if (msg.VendorId == 0)
                {
                    var booldata = saveNotification(chat);
                }
                else
                {
                    var bdata = saveNotiForCust(chat);
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }