Пример #1
0
        public JsonResult NoAnswer(int id)
        {
            Response response = null;

            try
            {
                int userId = GetAuthenticatedUserId();
                using (KiaGalleryContext db = new KiaGalleryContext())
                {
                    var item = db.BotOrder.First(x => x.Id == id);
                    item.Status = BotOrderStatus.RejectCall;
                    BotOrderLog log = new BotOrderLog()
                    {
                        OrderId      = item.Id,
                        Status       = BotOrderStatus.RejectCall,
                        CreateUserId = userId,
                        CreateDate   = DateTime.Now,
                        Ip           = Request.UserHostAddress
                    };
                    db.BotOrderLog.Add(log);
                    db.SaveChanges();
                }

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

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public JsonResult SaveMainInfo(int id, string firstName, string lastName, string description)
        {
            Response response = null;

            try
            {
                int userId = GetAuthenticatedUserId();
                List <BotSettings> settings;
                BotUserData        userData;
                using (KiaGalleryContext db = new KiaGalleryContext())
                {
                    var item = db.BotOrder.First(x => x.Id == id);
                    item.Status      = BotOrderStatus.PendingPrepayment;
                    item.FirstName   = firstName;
                    item.LastName    = lastName;
                    item.Description = description;
                    //item.AnswerDate = DateTime.Now;
                    BotOrderLog log = new BotOrderLog()
                    {
                        OrderId      = item.Id,
                        Status       = BotOrderStatus.PendingPrepayment,
                        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)
                {
                    Bot.SendTextMessageAsync(userData.ChatId, settings.First(x => x.Key == "SaveMainInfoText").ValueFa, Telegram.Bot.Types.Enums.ParseMode.Html, false, false);
                    Bot.SendTextMessageAsync(userData.ChatId, settings.First(x => x.Key == "AccountInfo").ValueFa, Telegram.Bot.Types.Enums.ParseMode.Html, false, false);
                }
                else
                {
                    Bot.SendTextMessageAsync(userData.ChatId, settings.First(x => x.Key == "SaveMainInfoText").Value, Telegram.Bot.Types.Enums.ParseMode.Html, false, false);
                    Bot.SendTextMessageAsync(userData.ChatId, settings.First(x => x.Key == "AccountInfo").Value, Telegram.Bot.Types.Enums.ParseMode.Html, false, false);
                }

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

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public JsonResult Built(int id)
        {
            Response response = null;

            try
            {
                int userId = GetAuthenticatedUserId();
                //List<BotSettings> settings;
                //UserData userData;
                using (KiaGalleryContext db = new KiaGalleryContext())
                {
                    var item = db.BotOrder.First(x => x.Id == id);
                    item.Status = BotOrderStatus.PendingPayment;
                    //item.BuildDate = DateTime.Now;
                    BotOrderLog log = new BotOrderLog()
                    {
                        OrderId      = item.Id,
                        Status       = BotOrderStatus.PendingPayment,
                        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)
                //    Bot.SendTextMessageAsync(userData.ChatId, settings.First(x => x.Key == "BuiltComplete").ValueFa, false, false);
                //else
                //    Bot.SendTextMessageAsync(userData.ChatId, settings.First(x => x.Key == "BuiltComplete").Value, false, false);

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

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Пример #4
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));
        }