Esempio n. 1
0
        public JsonResult GetDetail(int id)
        {
            Response response;

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    var detailList = db.WorkShopGold.Where(x => x.WorkshopId == id).Select(x => new WorkShopDetailViewModel {
                        weight          = x.Weight,
                        date            = x.Date,
                        name            = x.Workshop.Name,
                        goldRate        = x.GoldRate,
                        boughtGoldPrice = x.BoughtGoldPrice
                    }).ToList();
                    detailList.ForEach(x =>
                    {
                        x.stringDate = DateUtility.GetPersianDateTime(x.date);
                    });
                    response = new Response()
                    {
                        status = 200,
                        data   = new
                        {
                            list = detailList
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public ActionResult ViewOrder(int id)
        {
            BotOrder item;

            using (KiaGalleryContext db = new KiaGalleryContext())
            {
                item = db.BotOrder.Include(x => x.BotOrderLogList).First(x => x.Id == id);
            }

            ViewBag.Id          = id;
            ViewBag.Title       = item.PhoneNumber + " (" + item.FirstName + " " + item.LastName + ")";
            ViewBag.PhoneNumber = item.PhoneNumber;
            ViewBag.FirstName   = item.FirstName;
            ViewBag.LastName    = item.LastName;
            ViewBag.Description = item.Description;
            ViewBag.Deposit     = item.Deposit;
            ViewBag.CardDetails = item.CardDetails;
            ViewBag.Address     = item.Address;
            ViewBag.PaymentType = item.PaymentType;
            ViewBag.Status      = item.Status;
            ViewBag.StatusText  = Enums.GetTitle(item.Status);
            ViewBag.DataId      = item.ProductId;

            ViewBag.CreatedDate      = DateUtility.GetPersianDateTime(item.CreatedDate);
            ViewBag.AnswerDate       = DateUtility.GetPersianDateTime(item.BotOrderLogList.FirstOrDefault(x => x.Status == BotOrderStatus.PendingPrepayment).CreateDate);
            ViewBag.FirstPaymentDate = DateUtility.GetPersianDateTime(item.BotOrderLogList.FirstOrDefault(x => x.Status == BotOrderStatus.UnderConstruction).CreateDate);
            ViewBag.BuildDate        = DateUtility.GetPersianDateTime(item.BotOrderLogList.FirstOrDefault(x => x.Status == BotOrderStatus.PendingPayment).CreateDate);
            ViewBag.SendDate         = DateUtility.GetPersianDateTime(item.BotOrderLogList.FirstOrDefault(x => x.Status == BotOrderStatus.Sent).CreateDate);

            return(View());
        }
Esempio n. 3
0
        public JsonResult Load(int id)
        {
            try
            {
                var entity = _context.Coupon.Where(x => x.StatusId != CouponStatus.Deleted.Id && x.Id == id).Select(x => new CouponViewModel()
                {
                    id          = x.Id,
                    code        = x.Code,
                    typeId      = x.TypeId,
                    typeTitle   = x.Type.PersianTitle,
                    value       = x.Value,
                    usedCount   = x.UsedCount,
                    usableCount = x.UsableCount,
                    userId      = x.UserId,
                    fromDate    = x.FromDate,
                    toDate      = x.ToDate,
                    statusId    = x.StatusId,
                    statusTitle = x.Status.PersianTitle
                }).Single();

                entity.fromDatePersian = DateUtility.GetPersianDateTime(entity.fromDate);
                entity.toDatePersian   = DateUtility.GetPersianDateTime(entity.toDate);

                return(Success(entity));
            }
            catch (Exception ex)
            {
                return(ServerError(ex));
            }
        }
Esempio n. 4
0
        public JsonResult GetBranchFiles(MarquisFileSearchViewModel model)
        {
            Response response;

            try
            {
                var user = GetAuthenticatedUser();
                List <MarquisFileViewModel> list;
                int dataCount;
                using (var db = new KiaGalleryContext())
                {
                    var query = db.MarquisFile.Where(x => x.BranchId == user.BranchId);

                    if (!string.IsNullOrEmpty(model.date))
                    {
                        var date = DateUtility.GetDateTime(model.date);
                        query = query.Where(x => DbFunctions.TruncateTime(x.CreateDate) == DbFunctions.TruncateTime(date));
                    }

                    dataCount = query.Count();
                    query     = query.OrderByDescending(x => x.Id).Skip(model.page * model.count).Take(model.count);
                    list      = query.Select(item => new MarquisFileViewModel()
                    {
                        id          = item.Id,
                        branchId    = item.BranchId,
                        branchName  = item.Branch.Name,
                        description = item.Description,
                        fileCount   = item.MarquisFileDetailList.Count,
                        date        = item.CreateDate
                    }).ToList();
                }

                list.ForEach(x => x.persianDate = DateUtility.GetPersianDateTime(x.date));

                response = new Response()
                {
                    status = 200,
                    data   = new
                    {
                        list      = list,
                        pageCount = Math.Ceiling((double)dataCount / model.count),
                        count     = dataCount,
                        page      = model.page + 1
                    }
                };
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 5
0
        public JsonResult GetBranchGold(string date)
        {
            Response response;

            try
            {
                var dateTime = DateUtility.GetDateTime(date);
                using (var db = new KiaGalleryContext())
                {
                    var query = db.BranchGold.OrderByDescending(x => x.Branch.Order).Where(x => DbFunctions.TruncateTime(x.Date) == dateTime);

                    var list = query.GroupBy(x => x.BranchId).Select(x => new GetBranchGoldViewModel()
                    {
                        branchName = x.FirstOrDefault().Branch.Name,
                        weight     = x.Sum(y => y.Weight),
                        price      = x.Sum(y => y.Price),
                        date       = x.OrderByDescending(y => y.Date).FirstOrDefault().Date,
                        detail     = x.Select(y => new DetailSearchViewModel
                        {
                            weight = y.Weight,
                            date   = y.Date,
                        }).ToList(),
                    }).ToList();
                    list.ForEach(x =>
                    {
                        x.detail.ForEach(y =>
                        {
                            y.stringDate = DateUtility.GetPersianDateTime(y.date);
                        });
                        x.stringDate = DateUtility.GetPersianDateTime(x.date);
                    });

                    response = new Response()
                    {
                        status = 200,
                        data   = new
                        {
                            list      = list,
                            weightSum = list.Sum(x => x.weight),
                            priceSum  = list.Sum(x => x.price)
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 6
0
        /// <summary>
        /// جستجوی لیست فاکتور های کاربر
        /// </summary>
        /// <param name="model">مدل حاوی اطلاعات جستجو</param>
        /// <returns>نتیجه جستجوی کاربر</returns>
        public JsonResult List(SearchInvoiceViewModel options)
        {
            try
            {
                var currentUser = GetAuthenticatedUser();
                var query       = _context.Invoice.Where(x => x.InvoiceStatusId != InvoiceStatus.Deleted.Id && x.UserId == currentUser.id);

                if (!string.IsNullOrEmpty(options.word))
                {
                    var word = options.word.ToStandardPersian();
                    query = query.Where(x =>
                                        //x.DetailList.Any(y => y.Product.Title.Contains(word)) ||
                                        x.DetailList.Any(y => y.Product.Code.Contains(word)) ||
                                        x.InvoiceNo.Contains(word) ||
                                        x.User.FirstName.Contains(word) ||
                                        x.User.LastName.Contains(word) ||
                                        x.User.MobileNumber.Contains(word) ||
                                        x.User.Email.Contains(word)
                                        );
                }

                if (options.statusList != null && options.statusList.Count(x => x > 0) > 0)
                {
                    query = query.Where(x => options.statusList.Any(y => y == x.InvoiceStatusId));
                }

                var count = query.Count();

                var data = query.OrderByDescending(x => x.Id)
                           .Skip(options.page * options.count)
                           .Take(options.count)
                           .Select(x => new ResponseUserSearchInvoiceViewModel()
                {
                    id                 = x.Id,
                    invoiceNo          = x.InvoiceNo,
                    invoiceStatusId    = x.InvoiceStatusId,
                    invoiceStatusTitle = x.InvoiceStatus.PersianTitle,
                    price              = x.Price,
                    unpaidPrice        = x.UnpaidPrice,
                    date               = x.CreateDate
                }).ToList();

                data.ForEach(x => x.PersianDate = DateUtility.GetPersianDateTime(x.date));

                return(SuccessSearch(data, options.page + 1, options.count, count));
            }
            catch (Exception ex)
            {
                return(ServerError(ex));
            }
        }
Esempio n. 7
0
        public JsonResult InquiryList(InquiryProductSearchViewModel model)
        {
            Response response;
            var      user = GetAuthenticatedUser();

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    var query     = db.InquiryProduct.Select(x => x);
                    var dataCount = query.Count();

                    List <InquiryProductViewModel> inquiryList = query.OrderByDescending(x => x.Id).Skip(model.page * model.count).Take(model.count).Select(x => new InquiryProductViewModel()
                    {
                        id           = x.Id,
                        imageLink    = "/upload/user/" + user.FileName,
                        productCode  = x.Product.Code,
                        productTitle = x.Product.Title,
                        branchId     = x.BranchId,
                        branchName   = x.Branch.Name,
                        comment      = x.Comment,
                        createdDate  = x.CreateDate,
                        commentCount = x.InquiryProductReplyList.Where(y => !string.IsNullOrEmpty(y.Comment)).Count(),
                    }).ToList();

                    inquiryList.ForEach(x =>
                    {
                        x.productTypeTitle   = Enums.GetTitle(x.productType);
                        x.persianCreatedDate = DateUtility.GetPersianDateTime(x.createdDate);
                    });

                    response = new Response
                    {
                        status = 200,
                        data   = new
                        {
                            list      = inquiryList,
                            pageCount = Math.Ceiling((double)dataCount / model.count),
                            count     = dataCount,
                            page      = model.page + 1
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 8
0
        public JsonResult GetData(int page, int count)
        {
            Response response;

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    var query = db.BotBroadcast.Select(x => new
                    {
                        x.Id,
                        x.BroadcastType,
                        x.Text,
                        x.FileName,
                        x.CreatedDate
                    });

                    var data      = query.OrderByDescending(x => x.Id).Skip(page * count).Take(count).ToList();
                    int dataCount = query.Count();

                    var listData = data.Select(x => new
                    {
                        id                 = x.Id,
                        type               = Enums.GetTitle(x.BroadcastType.GetValueOrDefault()),
                        text               = x.Text,
                        fileName           = x.FileName,
                        persianCreatedDate = DateUtility.GetPersianDateTime(x.CreatedDate.GetValueOrDefault())
                    }).ToList();

                    response = new Response()
                    {
                        status = 200,
                        data   = new
                        {
                            list      = listData,
                            pageCount = Math.Ceiling((double)dataCount / count),
                            count     = dataCount,
                            pageNo    = page + 1
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 9
0
        public JsonResult Search(SearchMessageBoxViewModel options)
        {
            try
            {
                var query = _context.MessageBox.Where(x => x.StatusId != MessageBoxStatus.Deleted.Id);
                if (options.typeId > 0 && options.typeId == 3)
                {
                    query = query.Where(x => x.MessageTypeId == MessageType.ContactUs.Id);
                }
                if (options.typeId > 0 && options.typeId == 2)
                {
                    query = query.Where(x => x.MessageTypeId == MessageType.WorkWithUs.Id);
                }
                if (options.typeId > 0 && options.typeId == 1)
                {
                    query = query.Where(x => x.MessageTypeId == MessageType.Designer.Id);
                }
                if (!string.IsNullOrEmpty(options.word))
                {
                    var word = options.word.ToStandardPersian();
                    query = query.Where(x => x.FullName.Contains(word) || x.Email.Contains(word));
                }

                var count = query.Count();

                var data = query.OrderByDescending(x => x.CreateDate)
                           .Skip(options.page * options.count)
                           .Take(options.count)
                           .Select(x => new MessageBoxViewModel()
                {
                    id           = x.Id,
                    fullName     = x.FullName,
                    mobileNumber = x.MobileNumber,
                    email        = x.Email,
                    statusId     = x.StatusId,
                    statusTitle  = x.Status.PersianTitle,
                    createDate   = x.CreateDate
                }).ToList();

                data.ForEach(x => x.PersianCreateDate = DateUtility.GetPersianDateTime(x.createDate));

                return(SuccessSearch(data, options.page + 1, options.count, count, "createDate", "asc"));
            }
            catch (Exception ex)
            {
                return(ServerError(ex));
            }
        }
Esempio n. 10
0
        public JsonResult Search(string date)
        {
            Response response;

            try
            {
                var currentUser = GetAuthenticatedUser();
                var dateTime    = DateUtility.GetDateTime(date);
                using (var db = new KiaGalleryContext())
                {
                    var query        = db.GoldBalance.OrderByDescending(x => x.Id).Where(x => DbFunctions.TruncateTime(x.Date) == dateTime);
                    var workShopGold = db.WorkShopGold.Where(x => DbFunctions.TruncateTime(x.Date) == dateTime).Select(x => x.Weight).ToList().Sum();

                    var list = query.Select(x => new GoldBalanceSearchViewModel()
                    {
                        id          = x.Id,
                        date        = x.Date,
                        weight      = x.Weight,
                        description = x.Description,
                        dealerName  = x.DealerName,
                        tradeType   = x.TradeType,
                        tradeTime   = x.TradeTime,
                    }).ToList();
                    list.ForEach(x =>
                    {
                        x.tradeTypeTitle = Enums.GetTitle(x.tradeType);
                        x.stringDate     = DateUtility.GetPersianDateTime(x.date);
                    });

                    response = new Response()
                    {
                        status = 200,
                        data   = new
                        {
                            list      = list,
                            weightSum = list.Where(x => x.tradeType == TradeType.Buy).Sum(x => x.weight) - list.Where(x => x.tradeType == TradeType.Sell).Sum(x => x.weight)
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 11
0
        public JsonResult Search(SearchCouponViewModel options)
        {
            try
            {
                var query = _context.Coupon.Where(x => x.StatusId != CouponStatus.Deleted.Id);

                if (!string.IsNullOrEmpty(options.word))
                {
                    var word = options.word.ToStandardPersian();
                    query = query.Where(x => x.Code.Contains(word));
                }

                var count = query.Count();

                var data = query.OrderByDescending(x => x.Id)
                           .Skip(options.page * options.count)
                           .Take(options.count)
                           .Select(x => new CouponViewModel()
                {
                    id          = x.Id,
                    code        = x.Code,
                    typeId      = x.TypeId,
                    typeTitle   = x.Type.PersianTitle,
                    value       = x.Value,
                    usedCount   = x.UsedCount,
                    usableCount = x.UsableCount,
                    userId      = x.UserId,
                    fromDate    = x.FromDate,
                    toDate      = x.ToDate,
                    statusId    = x.StatusId,
                    statusTitle = x.Status.PersianTitle
                }).ToList();

                data.ForEach(x =>
                {
                    x.fromDatePersian = DateUtility.GetPersianDateTime(x.fromDate);
                    x.toDatePersian   = DateUtility.GetPersianDateTime(x.toDate);
                });

                return(SuccessSearch(data, options.page + 1, options.count, count));
            }
            catch (Exception ex)
            {
                return(ServerError(ex));
            }
        }
Esempio n. 12
0
        public JsonResult Search(SearchTicketViewModel model)
        {
            Response response;
            var      currentUser = GetAuthenticatedUser();

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    var query = db.Ticket.Where(x => x.FromUserId == currentUser.Id || x.ToUserId == currentUser.Id).Select(x => x);
                    var list  = query.Select(x => new TicketViewModel
                    {
                        id           = x.Id,
                        title        = x.Title,
                        text         = x.TicketMessagesList.OrderByDescending(y => y.Id).Select(y => y.Text).FirstOrDefault(),
                        ticketStatus = x.TicketStatus,
                        createDate   = x.CreateDate,
                        toUserId     = x.ToUserId,
                        fromUserName = x.FromUser.FirstName + " " + x.FromUser.LastName,
                        toUserName   = x.ToUser.FirstName + " " + x.ToUser.LastName,
                    }).ToList();
                    var dataCount = query.Count();
                    list.ForEach(x =>
                    {
                        x.ticketStatusTitle = Enums.GetTitle(x.ticketStatus);
                        x.persianDate       = DateUtility.GetPersianDateTime(x.createDate);
                    });
                    response = new Response()
                    {
                        status = 200,
                        data   = new
                        {
                            list      = list,
                            pageCount = Math.Ceiling((double)dataCount / model.count),
                            count     = dataCount,
                            page      = model.page + 1
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 13
0
        public JsonResult GetBarcode(string barcode)
        {
            Response response;

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    var item = db.CrmInvoiceDetail.Where(x => x.Invoice.InvoiceType == Model.CrmInvoiceType.Purchase && x.Barcode == barcode).OrderByDescending(x => x.CreateDate).Select(x => new InvoiceDetailViewModel
                    {
                        id         = x.Id,
                        barcode    = x.Barcode,
                        branchName = x.Invoice.Branch.Name,
                        date       = x.CreateDate,
                        revocation = x.Revocation,
                        goldPrice  = x.Invoice.GoldPrice.ToString()
                    }).FirstOrDefault();

                    if (item != null)
                    {
                        item.persianDate = DateUtility.GetPersianDateTime(item.date);
                        item.goldPrice   = Core.ToSeparator(int.Parse(item.goldPrice));

                        response = new Response()
                        {
                            status = 200,
                            data   = item
                        };
                    }
                    else
                    {
                        response = new Response()
                        {
                            status  = 500,
                            message = "بارکد مورد نظر یافت نشد."
                        };
                    }
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 14
0
        public JsonResult Search(string date)
        {
            Response response;

            try
            {
                var currentUser = GetAuthenticatedUser();
                var dateTime    = DateUtility.GetDateTime(date);
                using (var db = new KiaGalleryContext())
                {
                    var query = db.BranchGold.OrderByDescending(x => x.Id).Where(x => DbFunctions.TruncateTime(x.Date) == dateTime && x.BranchId == currentUser.BranchId);

                    var list = query.Select(x => new BranchGoldSearchViewModel()
                    {
                        id     = x.Id,
                        date   = x.Date,
                        weight = x.Weight,
                        price  = x.Price
                    }).ToList();

                    list.ForEach(x =>
                    {
                        x.stringDate  = DateUtility.GetPersianDateTime(x.date);
                        x.stringPrice = Core.ToSeparator(x.price);
                    });
                    response = new Response()
                    {
                        status = 200,
                        data   = new
                        {
                            list      = list,
                            weightSum = list.Sum(x => x.weight),
                            priceSum  = list.Sum(x => x.price)
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 15
0
        public JsonResult SearchLog(int id)
        {
            Response response;

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    var query = db.LoyalityCardLog.Where(x => x.LoyalityCardId == id);

                    var list = query.Select(x => new LoyalityCardViewModel
                    {
                        id         = x.Id,
                        createDate = x.CreateDate,
                        cardStatus = x.CardStatus,
                        createUser = x.CreateUser.FirstName + " " + x.CreateUser.LastName,
                        branchName = x.LoyalityCard.Branch.Name,
                    }).ToList();
                    list.ForEach(x =>
                    {
                        x.persianCreateDate = DateUtility.GetPersianDateTime(x.createDate);
                        x.cardStatusTitle   = Enums.GetTitle(x.cardStatus);
                        x.cardTypeTitle     = Enums.GetTitle(x.cardType);
                    });
                    response = new Response()
                    {
                        status = 200,
                        data   = new
                        {
                            list = list
                        }
                    };
                };
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 16
0
        public JsonResult InquiryReplyList()
        {
            Response response;
            var      user = GetAuthenticatedUser();

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    List <InquiryProductReplyViewModel> replyList = db.InquiryProductReply.OrderByDescending(x => x.Id).Select(x => new InquiryProductReplyViewModel()
                    {
                        id               = x.Id,
                        branchId         = x.BranchId,
                        branchName       = x.Branch.Name,
                        comment          = x.Comment,
                        answerType       = x.AnswerType,
                        inquiryProductId = x.InquiryProductId,
                        createdDate      = x.CreateDate
                    }).ToList();

                    replyList.ForEach(x => x.persianCreatedDate = DateUtility.GetPersianDateTime(x.createdDate));
                    response = new Response
                    {
                        status = 200,
                        data   = new
                        {
                            list = replyList
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 17
0
        public JsonResult GetUserChat(int chatId, int lastId)
        {
            Response response;

            try
            {
                List <BotMessage> result;
                using (var db = new KiaGalleryContext())
                {
                    result = db.BotMessage.Where(x => x.ChatId == chatId && x.Id > lastId && x.Unknown == true).OrderBy(x => x.Id).Take(100).ToList();
                }
                var data = result.Select(x => new
                {
                    id          = x.Id,
                    messageId   = x.MessageId,
                    text        = x.Text,
                    createdDate = DateUtility.GetPersianDateTime(x.CreatedDate.GetValueOrDefault()),
                    unknown     = x.Unknown,
                    replyId     = x.ReplayMessageId
                }).OrderBy(x => x.id).ToList();

                response = new Response()
                {
                    status = 200,
                    data   = new
                    {
                        list = data
                    }
                };
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 18
0
        public JsonResult GetData(int page, int count, string nameQuery, string orderNo, BotOrderStatus[] status, string fromDate, string toDate)
        {
            Response response;

            try
            {
                using (KiaGalleryContext db = new KiaGalleryContext())
                {
                    var query = db.BotOrder.Where(x => status.Any(y => y == x.Status));

                    if (!string.IsNullOrEmpty(orderNo))
                    {
                        query = query.Where(x => x.OrderSerial.Contains(orderNo));
                    }

                    if (!string.IsNullOrEmpty(nameQuery))
                    {
                        query = query.Where(x => (x.FirstName.Contains(nameQuery) || x.LastName.Contains(nameQuery) || x.PhoneNumber.Contains(nameQuery)));
                    }

                    if (string.IsNullOrEmpty(nameQuery) && string.IsNullOrEmpty(orderNo) && !string.IsNullOrEmpty(fromDate))
                    {
                        DateTime?_fromDate = DateUtility.GetDateTime(fromDate);
                        if (_fromDate != null)
                        {
                            query = query.Where(x => x.CreatedDate >= _fromDate);
                        }
                    }

                    if (string.IsNullOrEmpty(nameQuery) && string.IsNullOrEmpty(orderNo) && !string.IsNullOrEmpty(toDate))
                    {
                        DateTime?_toDate = DateUtility.GetDateTime(toDate);
                        if (_toDate != null)
                        {
                            _toDate = _toDate.Value.AddDays(1);
                            query   = query.Where(x => x.CreatedDate <= _toDate);
                        }
                    }

                    query.Select(x => new
                    {
                        x.Id,
                        x.ChatId,
                        x.OrderSerial,
                        x.Status,
                        x.FirstName,
                        x.LastName,
                        x.PhoneNumber,
                        x.CreatedDate
                    });

                    var data      = query.OrderByDescending(x => x.Id).Skip(page * count).Take(count).ToList();
                    int dataCount = query.Count();

                    var listData = data.Select(x => new
                    {
                        id          = x.Id,
                        chatId      = x.ChatId,
                        orderNo     = x.OrderSerial,
                        status      = x.Status,
                        statusText  = Enums.GetTitle(x.Status),
                        firstName   = x.FirstName,
                        lastName    = x.LastName,
                        phoneNumber = x.PhoneNumber,
                        createdDate = DateUtility.GetPersianDateTime(x.CreatedDate),
                    }).ToList();

                    response = new Response()
                    {
                        status = 200,
                        data   = new
                        {
                            list      = listData,
                            pageCount = Math.Ceiling((double)dataCount / count),
                            count     = dataCount,
                            pageNo    = page + 1
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 19
0
        public JsonResult LoadDetail(int id)
        {
            try
            {
                var currentUser = GetAuthenticatedUser();
                var invoice     = _context.Invoice.Where(x => x.InvoiceStatusId != InvoiceStatus.Deleted.Id && x.Id == id).Select(x => new InvoiceViewModel()
                {
                    id                   = x.Id,
                    userId               = x.UserId,
                    firstName            = x.User.FirstName,
                    lastName             = x.User.LastName,
                    invoiceStatusId      = x.InvoiceStatusId,
                    invoiceStatusTitle   = x.InvoiceStatus.PersianTitle,
                    paymentTypeId        = x.PaymentTypeId,
                    paymentTypeTitle     = x.PaymentType.PersianTitle,
                    deliveryTypeId       = x.DeliveryTypeId,
                    deliveryTypeTitle    = x.DeliveryType.PersianTitle,
                    invoiceNo            = x.InvoiceNo,
                    price                = x.Price,
                    unpaidPrice          = x.UnpaidPrice,
                    deliveryPrice        = x.DeliveryPrice,
                    addressId            = x.AddressId,
                    receiverFullName     = x.Address.ReceiverFullName,
                    receiverMobileNumber = x.Address.ReceiverMobileNumber,
                    phoneNumber          = x.Address.PhoneNumber,
                    provinceId           = x.Address.ProvinceId,
                    provinceTitle        = x.Address.Province.Title,
                    cityId               = x.Address.CityId,
                    cityTitle            = x.Address.City.Title,
                    postalCode           = x.Address.PostalCode,
                    address              = x.Address.Address,
                    deliveryDate         = x.DeliveryDate,
                    deliveryTime         = x.DeliveryTime,
                    description          = x.Description,
                    couponId             = x.CouponId,
                    couponCode           = x.Coupon.Code,
                    createDate           = x.CreateDate,
                    detailList           = x.DetailList.Where(y => y.StatusId != InvoiceDetailStatus.Deleted.Id).Select(y => new InvoiceDetailViewModel()
                    {
                        id                   = y.Id,
                        invoiceId            = y.InvoiceId,
                        productId            = y.ProductId,
                        productTitle         = y.Product.Sku,
                        productFileId        = y.Product.FileId,
                        productFileName      = y.Product.FileName,
                        productCategoryTitle = y.Product.Category.Sku,
                        productBrandTitle    = y.Product.Brand.Sku,
                        featureTitle         = y.ProductFeature.CategoryFeatureValue.CategoryFeature.Sku,
                        productFeatureId     = y.ProductFeatureId,
                        productFeatureTitle  = y.ProductFeature.CategoryFeatureValue.Sku,
                        count                = y.Count,
                        price                = y.Price
                    }).ToList(),
                    logList = x.InvoiceLogList.Select(y => new InvoiceLogViewModel()
                    {
                        id          = y.Id,
                        invoiceId   = y.InvoiceId,
                        statusId    = y.StatusId,
                        statusTitle = y.Status.PersianTitle,
                        description = y.Description,
                        date        = y.CreateDate,
                        firstName   = y.CreateUser.FirstName,
                        lastName    = y.CreateUser.LastName
                    }).ToList()
                }).Single();

                invoice.PersianDeliveryDate = DateUtility.GetPersianDate(invoice.deliveryDate);
                invoice.PersianCreateDate   = DateUtility.GetPersianDateTime(invoice.createDate, " - ");
                invoice.detailList.ForEach(x => x.productUrlTitle = x.productTitle.ToUrlString());
                invoice.logList.ForEach(x => x.PersianDate        = DateUtility.GetPersianDateTime(x.date));

                return(Success(invoice));
            }
            catch (Exception ex)
            {
                return(ServerError(ex));
            }
        }
Esempio n. 20
0
        public JsonResult SavePrePayment(int id, int deposit, string cardDetails)
        {
            Response response = null;

            try
            {
                int userId = GetAuthenticatedUserId();
                List <BotSettings> settings;
                BotUserData        userData;
                BotOrder           item;
                using (KiaGalleryContext db = new KiaGalleryContext())
                {
                    item             = db.BotOrder.Include(x => x.BotOrderLogList).Include(x => x.Product).First(x => x.Id == id);
                    item.Status      = BotOrderStatus.UnderConstruction;
                    item.Deposit     = deposit;
                    item.CardDetails = cardDetails;
                    // item.FirstPaymentDate = DateTime.Now;
                    BotOrderLog log = new BotOrderLog()
                    {
                        OrderId      = item.Id,
                        Status       = BotOrderStatus.UnderConstruction,
                        CreateUserId = userId,
                        CreateDate   = DateTime.Now,
                        Ip           = Request.UserHostAddress
                    };
                    db.BotOrderLog.Add(log);

                    settings = db.BotSettings.ToList();
                    userData = db.BotUserData.First(x => x.ChatId == item.ChatId);

                    db.SaveChanges();
                }

                TelegramBotClient Bot = new TelegramBotClient(settings.First(x => x.Key == "BotApi").Value);
                if (userData.Language == 0)
                {
                    string message = settings.First(x => x.Key == "SavePrePaymentText").ValueFa
                                     .Replace("{Name}", item.FirstName + " " + item.LastName)
                                     .Replace("{Date}", DateUtility.GetPersianDateTime(DateTime.Now))
                                     .Replace("{OrderNo}", item.OrderSerial)
                                     .Replace("{Code}", item.Product.Code)
                                     .Replace("{Desc}", item.Description)
                                     .Replace("{Price}", deposit.ToString());


                    if (string.IsNullOrEmpty(item.Product.ProductFileList.FirstOrDefault(x => x.FileType == FileType.Bot).FileId))
                    {
                        string     filePath = "/Upload/Product/" + item.Product.ProductFileList.FirstOrDefault(x => x.FileType == FileType.Bot).FileName;
                        Stream     stream   = System.IO.File.OpenRead(filePath);
                        FileToSend file     = new FileToSend(System.IO.Path.GetFileName(filePath), stream);
                        Bot.SendPhotoAsync(userData.ChatId, file, message, false, 0);
                    }
                    else
                    {
                        FileToSend file = new FileToSend(item.Product.ProductFileList.FirstOrDefault(x => x.FileType == FileType.Bot).FileId);
                        Bot.SendPhotoAsync(userData.ChatId, file, message, false, 0);
                    }
                }
                else
                {
                    string message = settings.First(x => x.Key == "SavePrePaymentText").Value
                                     .Replace("{Name}", item.FirstName + " " + item.LastName)
                                     .Replace("{Date}", DateUtility.GetPersianDateTime(DateTime.Now))
                                     .Replace("{OrderNo}", item.OrderSerial)
                                     .Replace("{Code}", item.Product.Code)
                                     .Replace("{Desc}", item.Description)
                                     .Replace("{Price}", deposit.ToString());

                    if (string.IsNullOrEmpty(item.Product.ProductFileList.FirstOrDefault(x => x.FileType == FileType.Bot).FileId))
                    {
                        string     filePath = "/Upload/Data/" + item.Product.ProductFileList.FirstOrDefault(x => x.FileType == FileType.Bot).FileName;
                        Stream     stream   = System.IO.File.OpenRead(filePath);
                        FileToSend file     = new FileToSend(System.IO.Path.GetFileName(filePath), stream);
                        Bot.SendPhotoAsync(userData.ChatId, file, message, false, 0);
                    }
                    else
                    {
                        FileToSend file = new FileToSend(item.Product.ProductFileList.FirstOrDefault(x => x.FileType == FileType.Bot).FileId);
                        Bot.SendPhotoAsync(userData.ChatId, file, message, false, 0);
                    }
                }

                response = new Response()
                {
                    status = 200
                };
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 21
0
        public JsonResult Search(BranchInventoryViewModel model)
        {
            Response response;

            try
            {
                var currentUser = GetAuthenticatedUser();
                using (var db = new KiaGalleryContext())
                {
                    var query      = db.BranchInventory.Where(x => !x.Title.Contains("*"));
                    var lastUpdate = db.BranchInventory.Where(x => !x.Title.Contains("*"));

                    if (!string.IsNullOrEmpty(model.word))
                    {
                        query = query.Where(x => x.Title.Contains(model.word) || x.ProductCode.Contains(model.word));
                    }
                    var dataCount = query.Count();
                    query = query.OrderBy(x => x.Id).Skip(model.page * model.count).Take(model.count);
                    var list = query.Select(x => new BranchInventoryViewModel
                    {
                        title         = x.Title,
                        branchName    = x.Branch.Name,
                        productCode   = x.ProductCode,
                        weight        = x.Weight,
                        inventoryType = x.InventoryType,
                        date          = x.CreateDate
                    }).ToList();
                    list.ForEach(x =>
                    {
                        x.inventoryTypeTitle = Enums.GetTitle(x.inventoryType);
                        x.persianDate        = DateUtility.GetPersianDateTime(x.date);
                    });
                    var lastUpdateList = lastUpdate.GroupBy(x => x.Branch).Select(x => new LastUpdateListViewModel
                    {
                        branchName = x.Key.Name,
                        date       = x.OrderByDescending(y => y.CreateDate).FirstOrDefault().CreateDate
                    }).ToList();
                    lastUpdateList.ForEach(x =>
                    {
                        x.persianDate = DateUtility.GetPersianDateTime(x.date);
                    });
                    response = new Response()
                    {
                        status = 200,
                        data   = new
                        {
                            list      = list,
                            pageCount = Math.Ceiling((double)dataCount / model.count),
                            count     = dataCount,
                            page      = model.page + 1,
                            lastUpdateList
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }