public static OrderUI GetOrderById(Int64 OrderId, Int64 SupplierId = 0)
        {
            Query q = new Query(Order.TableSchema);

            // q.Join(JoinType.InnerJoin, Order.TableSchema, Order.Columns.BidId, Order.TableSchema.SchemaName,
            //  Offer.TableSchema, Offer.Columns.BidId, Offer.TableSchema.SchemaName);


            q.Join(JoinType.InnerJoin, Order.TableSchema, Order.Columns.SupplierId, Order.TableSchema.SchemaName,
                   AppSupplier.TableSchema, AppSupplier.Columns.SupplierId, AppSupplier.TableSchema.SchemaName);
            q.Join(JoinType.InnerJoin, Order.TableSchema, Order.Columns.AppUserId, Order.TableSchema.SchemaName,
                   AppUser.TableSchema, AppUser.Columns.AppUserId, AppUser.TableSchema.SchemaName);
            q.Join(JoinType.InnerJoin, AppUser.TableSchema, AppUser.Columns.CityId, AppUser.TableSchema.SchemaName,
                   City.TableSchema, City.Columns.CityId, City.TableSchema.SchemaName);
            q.OrderBy(Order.TableSchema.SchemaName, Order.Columns.CreateDate, SortDirection.DESC);
            q.Select(Order.TableSchema.SchemaName, Order.Columns.OrderId, Order.Columns.OrderId, true);
            q.AddSelect(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.BusinessName, AppSupplier.Columns.BusinessName);
            q.AddSelect(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.SupplierId, AppSupplier.Columns.SupplierId);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.CreateDate, Order.Columns.CreateDate);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.TotalPrice, Order.Columns.TotalPrice);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.BidId, Order.Columns.BidId);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.ReceivedDate, Order.Columns.ReceivedDate);
            q.AddSelect(City.TableSchema.SchemaName, City.Columns.CityName, City.Columns.CityName);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.Gifts, Order.Columns.Gifts);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.SuppliedDate, Order.Columns.SuppliedDate);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.AppUserId, Order.Columns.AppUserId);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.SpecialInstructions, Order.Columns.SpecialInstructions);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.IsSendRecived, Order.Columns.IsSendRecived);
            q.Where(Order.TableSchema.SchemaName, Order.Columns.OrderId, WhereComparision.EqualsTo, OrderId);

            if (SupplierId != 0)
            {
                q.AddWhere(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.SupplierId, WhereComparision.EqualsTo, SupplierId);
            }
            OrderUI orderUI = null;

            using (DataReaderBase reader = q.ExecuteReader())
            {
                if (reader.Read())
                {
                    orderUI = new OrderUI();
                    orderUI.SupplierName        = (reader[AppSupplier.Columns.BusinessName] != null ? reader[AppSupplier.Columns.BusinessName].ToString() : "");
                    orderUI.SupplierId          = (reader[AppSupplier.Columns.SupplierId] != null ? Int64.Parse(reader[AppSupplier.Columns.SupplierId].ToString()) : 0);
                    orderUI.OrderId             = (reader[Order.Columns.OrderId] != null ? Int64.Parse(reader[Order.Columns.OrderId].ToString()) : 0);
                    orderUI.OrderDate           = (reader[Order.Columns.CreateDate] != null ? DateTime.Parse(reader[Order.Columns.CreateDate].ToString()).ToLocalTime() : DateTime.MinValue);
                    orderUI.Price               = (reader[Order.Columns.TotalPrice] != null ? decimal.Parse(reader[Order.Columns.TotalPrice].ToString()) : 0);
                    orderUI.ReceviedDate        = (reader[Order.Columns.ReceivedDate] != null && (reader[Order.Columns.ReceivedDate]).ToString() != "" ? (DateTime?)Convert.ToDateTime(reader[Order.Columns.ReceivedDate]).ToLocalTime() : null);
                    orderUI.LstProduct          = BidController.GetProductsByBid(reader[Order.Columns.BidId] != null ? Int64.Parse(reader[Order.Columns.BidId].ToString()) : 0, orderUI.SupplierId);
                    orderUI.City                = (reader[City.Columns.CityName] != null ? reader[City.Columns.CityName].ToString() : "");
                    orderUI.user                = AppUser.FetchByID(Int64.Parse(reader[Order.Columns.AppUserId].ToString()));
                    orderUI.SuppliedDate        = (reader[Order.Columns.SuppliedDate] != null && (reader[Order.Columns.SuppliedDate]).ToString() != "" ? (DateTime?)Convert.ToDateTime(reader[Order.Columns.SuppliedDate]).ToLocalTime() : null);
                    orderUI.Gift                = (reader[Order.Columns.Gifts] != null ? reader[Order.Columns.Gifts].ToString() : "");
                    orderUI.SpecialInstructions = (reader[Order.Columns.SpecialInstructions] != null ? reader[Order.Columns.SpecialInstructions].ToString() : "");
                    orderUI.BidId               = (reader[Order.Columns.BidId] != null ? Int64.Parse(reader[Order.Columns.BidId].ToString()) : 0);
                    orderUI.IsSendReceived      = (reader[Order.Columns.IsSendRecived] != null) ? Convert.ToBoolean(reader[Order.Columns.IsSendRecived]) : false;
                }
            }
            return(orderUI);
        }
        public static List <OrderUI> GetOrderSupplierHistoryExcel(Int64 SupplierId, DateTime?StartDate = null, DateTime?EndDate = null)
        {
            Query q = new Query(Order.TableSchema);

            q.Join(JoinType.InnerJoin, Order.TableSchema, Order.Columns.SupplierId, Order.TableSchema.SchemaName,
                   AppSupplier.TableSchema, AppSupplier.Columns.SupplierId, AppSupplier.TableSchema.SchemaName);
            q.OrderBy(Order.TableSchema.SchemaName, Order.Columns.CreateDate, SortDirection.DESC);
            q.Select(Order.TableSchema.SchemaName, Order.Columns.OrderId, Order.Columns.OrderId, true);
            q.AddSelect(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.BusinessName, AppSupplier.Columns.BusinessName);
            q.AddSelect(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.SupplierId, AppSupplier.Columns.SupplierId);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.CreateDate, Order.Columns.CreateDate);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.BidId, Order.Columns.BidId);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.TotalPrice, Order.Columns.TotalPrice);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.TransactionResponseCode, Order.Columns.TransactionResponseCode);
            q.Where(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.SupplierId, WhereComparision.EqualsTo, SupplierId);
            if (StartDate != null && EndDate != null)
            {
                q.AddWhere(Order.TableSchema.SchemaName, Order.Columns.CreateDate, WhereComparision.GreaterThanOrEqual, StartDate);
                q.AddWhere(Order.TableSchema.SchemaName, Order.Columns.CreateDate, WhereComparision.LessThanOrEqual, EndDate.Value.AddDays(1));
            }
            List <OrderUI> LstOrder = new List <OrderUI>();

            using (DataReaderBase reader = q.ExecuteReader())
            {
                while (reader.Read())
                {
                    OrderUI orderUI = new OrderUI();
                    orderUI.SupplierName = (reader[AppSupplier.Columns.BusinessName] != null ? reader[AppSupplier.Columns.BusinessName].ToString() : "");
                    orderUI.SupplierId   = (reader[AppSupplier.Columns.SupplierId] != null ? Int64.Parse(reader[AppSupplier.Columns.SupplierId].ToString()) : 0);
                    orderUI.OrderId      = (reader[Order.Columns.OrderId] != null ? Int64.Parse(reader[Order.Columns.OrderId].ToString()) : 0);
                    orderUI.OrderDate    = (reader[Order.Columns.CreateDate] != null ? DateTime.Parse(reader[Order.Columns.CreateDate].ToString()).ToLocalTime() : DateTime.MinValue);
                    orderUI.BidId        = (reader[Order.Columns.BidId] != null ? Int64.Parse(reader[Order.Columns.BidId].ToString()) : 0);
                    orderUI.Price        = (reader[Order.Columns.TotalPrice] != null ? Int64.Parse(reader[Order.Columns.TotalPrice].ToString()) : 0);
                    orderUI.LstProduct   = BidController.GetProductsByBid(orderUI.BidId);
                    LstOrder.Add(orderUI);
                }
            }
            return(LstOrder);
        }
Example #3
0
        private void HandleAll(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            if (!Request.IsLocal)
            {
                Http.Respond404(true);
            }

            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);

            if (PathParams[0] == @"rematch")
            {
                using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                {
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                    {
                        jsonWriter.WriteStartObject();
                        try
                        {
                            jsonWriter.WritePropertyName(@"success");
                            jsonWriter.WriteValue(true);
                        }
                        catch (System.Exception ex)
                        {
                            jsonWriter.WritePropertyName(@"error");
                            jsonWriter.WriteValue(@"unknown");
                            jsonWriter.WritePropertyName(@"description");
                            jsonWriter.WriteValue(ex.ToString());
                        }
                        jsonWriter.WriteEndObject();
                    }
                }
            }
            else if (PathParams[0] == @"clean_tokens")
            {
                using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                {
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                    {
                        jsonWriter.WriteStartObject();
                        try
                        {
                            AuthTokens.DeleteAllExpired();


                            jsonWriter.WritePropertyName(@"success");
                            jsonWriter.WriteValue(true);
                        }
                        catch (System.Exception ex)
                        {
                            jsonWriter.WritePropertyName(@"error");
                            jsonWriter.WriteValue(@"unknown");
                            jsonWriter.WritePropertyName(@"description");
                            jsonWriter.WriteValue(ex.ToString());
                        }
                        jsonWriter.WriteEndObject();
                    }
                }
            }
            else if (PathParams[0] == @"offer")
            {
                //using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                //{
                //    using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                //    {
                //        jsonWriter.WriteStartObject();
                //        try
                //        {
                //            Query qry = new Query(Bid.TableSchema);
                //            qry.Where(Bid.Columns.IsSendOffer, WhereComparision.EqualsTo, false);
                //            qry.AddWhere(Bid.Columns.EndDate, WhereComparision.LessThan, DateTime.UtcNow);

                //            BidCollection bidCollection = BidCollection.FetchByQuery(qry);


                //            Query.New<Bid>().Where(Bid.Columns.IsSendOffer, WhereComparision.EqualsTo, false)
                //                .AddWhere(Bid.Columns.EndDate, WhereComparision.LessThan, DateTime.UtcNow)
                //                .Update(Bid.Columns.IsSendOffer, true)
                //                .Execute();

                //            foreach (Bid item in bidCollection)
                //            {
                //                Query q = new Query(Offer.TableSchema);
                //                q.Where(Offer.Columns.BidId, WhereComparision.EqualsTo, item.BidId);

                //                OfferCollection offerCollection = OfferCollection.FetchByQuery(q);
                //                if (offerCollection != null && offerCollection.Count > 0)
                //                {
                //                    if (item.AppUserId != null && item.AppUserId != 0)
                //                    {
                //                        Notification.SendNotificationAppUserOffers(string.Format(Snoopi.web.Localization.PushStrings.GetText("PushOfferText"), offerCollection.Count), (Int64)item.AppUserId, item.BidId);
                //                    }
                //                    else if (item.TempAppUserId != null && item.TempAppUserId != 0)
                //                    {
                //                        Notification.SendNotificationTempUserOffers(string.Format(Snoopi.web.Localization.PushStrings.GetText("PushOfferText"), offerCollection.Count), (Int64)item.TempAppUserId, item.BidId);
                //                    }
                //                }
                //                else
                //                {
                //                    if (item.AppUserId != null && item.AppUserId != 0)
                //                    {
                //                        Notification.SendNotificationAppUserOffers(Snoopi.web.Localization.PushStrings.GetText("NoPushOfferText"), (Int64)item.AppUserId, item.BidId);
                //                        AppUserUI user = AppUserUI.GetAppUserUI((Int64)item.AppUserId);
                //                        List<BidProductUI> products = BidController.GetProductsByBid(item.BidId);
                //                        Bid b = Bid.FetchByID(item.BidId);
                //                        string subject = GlobalStrings.GetText("MailToAdmin", new CultureInfo("he-IL"));
                //                        string body = GlobalStrings.GetText("SubjectMailToAdminOffers",new CultureInfo("he-IL"));
                //                        EmailMessagingService.SendMailNoOffersToAdmin(user, b.StartDate, products, subject, body);
                //                    }
                //                    else if (item.TempAppUserId != null && item.TempAppUserId != 0)
                //                    {
                //                        Notification.SendNotificationTempUserOffers(Snoopi.web.Localization.PushStrings.GetText("NoPushOfferText"), (Int64)item.TempAppUserId, item.BidId);
                //                    }

                //                }
                //                item.IsSendOffer = true;
                //                item.Save();

                //            }
                //            jsonWriter.WritePropertyName(@"success");
                //            jsonWriter.WriteValue(true);
                //        }
                //        catch (System.Exception ex)
                //        {
                //            //RespondError(Response, HttpStatusCode.BadRequest, ex.ToString());
                //            jsonWriter.WritePropertyName(@"error");
                //            jsonWriter.WriteValue(@"unknown");
                //            jsonWriter.WritePropertyName(@"description");
                //            jsonWriter.WriteValue(ex.ToString());
                //        }
                //        jsonWriter.WriteEndObject();
                //    }
                //}
            }
            else if (PathParams[0] == @"service_offer")
            {
                using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                {
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                    {
                        jsonWriter.WriteStartObject();
                        try
                        {
                            Query qry = new Query(BidService.TableSchema);
                            qry.Where(BidService.Columns.IsSendOffer, WhereComparision.EqualsTo, false);
                            qry.AddWhere(BidService.Columns.EndDate, WhereComparision.LessThan, DateTime.UtcNow);

                            BidServiceCollection bidCollection = BidServiceCollection.FetchByQuery(qry);
                            jsonWriter.WritePropertyName(@"qry");
                            jsonWriter.WriteValue(qry.ToString());

                            Query.New <BidService>().Where(BidService.Columns.IsSendOffer, WhereComparision.EqualsTo, false)
                            .AddWhere(BidService.Columns.EndDate, WhereComparision.LessThan, DateTime.UtcNow)
                            .Update(BidService.Columns.IsSendOffer, true)
                            .Execute();

                            foreach (BidService item in bidCollection)
                            {
                                Query q = new Query(OfferService.TableSchema);
                                q.Where(OfferService.Columns.BidId, WhereComparision.EqualsTo, item.BidId);

                                OfferServiceCollection offerCollection = OfferServiceCollection.FetchByQuery(q);
                                if (offerCollection != null && offerCollection.Count > 0)
                                {
                                    if (item.AppUserId != null && item.AppUserId != 0)
                                    {
                                        Notification.SendNotificationAppUserOffers(string.Format(Snoopi.web.Localization.PushStrings.GetText("PushOfferText"), offerCollection.Count), (Int64)item.AppUserId, item.BidId, true);
                                    }
                                    else if (item.TempAppUserId != null && item.TempAppUserId != 0)
                                    {
                                        Notification.SendNotificationTempUserOffers(string.Format(Snoopi.web.Localization.PushStrings.GetText("PushOfferText"), offerCollection.Count), (Int64)item.TempAppUserId, item.BidId, true);
                                    }
                                }
                                else
                                {
                                    if (item.AppUserId != null && item.AppUserId != 0)
                                    {
                                        Notification.SendNotificationAppUserOffers(Snoopi.web.Localization.PushStrings.GetText("NoPushOfferText"), (Int64)item.AppUserId, item.BidId, true);
                                        AppUserUI           user     = AppUserUI.GetAppUserUI((Int64)item.AppUserId);
                                        List <BidProductUI> products = BidController.GetProductsByBid(item.BidId);
                                        Bid    b       = Bid.FetchByID(item.BidId);
                                        string subject = GlobalStrings.GetText("MailToAdmin");
                                        string body    = GlobalStrings.GetText("SubjectMailToAdminOffers");
                                        EmailMessagingService.SendMailNoOffersToAdmin(user, b.StartDate, products, subject, body);
                                    }
                                    else if (item.TempAppUserId != null && item.TempAppUserId != 0)
                                    {
                                        Notification.SendNotificationTempUserOffers(Snoopi.web.Localization.PushStrings.GetText("NoPushOfferText"), (Int64)item.TempAppUserId, item.BidId, true);
                                    }
                                }
                                item.IsSendOffer = true;
                                item.Save();
                            }
                            jsonWriter.WritePropertyName(@"success");
                            jsonWriter.WriteValue(true);
                        }
                        catch (System.Exception ex)
                        {
                            //RespondError(Response, HttpStatusCode.BadRequest, ex.ToString());
                            jsonWriter.WritePropertyName(@"error");
                            jsonWriter.WriteValue(@"unknown");
                            jsonWriter.WritePropertyName(@"description");
                            jsonWriter.WriteValue(ex.ToString());
                        }
                        jsonWriter.WriteEndObject();
                    }
                }
            }
            else if (PathParams[0] == @"order_received")
            {
                using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                {
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                    {
                        jsonWriter.WriteStartObject();
                        try
                        {
                            Query qry = new Query(Order.TableSchema);
                            qry.Where(Order.Columns.IsSendRecived, WhereComparision.EqualsTo, false);
                            qry.AddWhere(Order.Columns.ReceivedDate, WhereComparision.EqualsTo, null);
                            qry.AddWhere(Order.Columns.UserPaySupplierStatus, WhereComparision.EqualsTo, UserPaymentStatus.Payed);
                            qry.AddWhere(Order.Columns.SuppliedDate, WhereComparision.LessThanOrEqual, DateTime.UtcNow.AddHours(-24));

                            OrderCollection orderCollection = OrderCollection.FetchByQuery(qry);

                            //Query.New<Order>().Where(Order.Columns.IsSendRecived, WhereComparision.EqualsTo, false)
                            //     .AddWhere(Order.Columns.ReceivedDate, WhereComparision.EqualsTo, null)
                            //     .AddWhere(Order.Columns.CreateDate, WhereComparision.LessThanOrEqual, DateTime.UtcNow.AddHours(-24))
                            //     .Update(Order.Columns.IsSendRecived, true)
                            //     .Execute();

                            foreach (Order item in orderCollection)
                            {
                                Notification.SendNotificationAppUserReceviedOrder(Snoopi.web.Localization.PushStrings.GetText("ReceivedOrder"), (Int64)item.AppUserId, item.OrderId);
                                item.IsSendRecived = true;
                                item.Save();
                            }

                            jsonWriter.WritePropertyName(@"success");
                            jsonWriter.WriteValue(true);
                        }
                        catch (System.Exception ex)
                        {
                            //RespondError(Response, HttpStatusCode.BadRequest, ex.ToString());
                            jsonWriter.WritePropertyName(@"error");
                            jsonWriter.WriteValue(@"unknown");
                            jsonWriter.WritePropertyName(@"description");
                            jsonWriter.WriteValue(ex.ToString());
                        }
                        jsonWriter.WriteEndObject();
                    }
                }
            }
            else if (PathParams[0] == @"auto_push")
            {
                using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                {
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                    {
                        jsonWriter.WriteStartObject();
                        try
                        {
                            var filters = NotificationGroups.GetAutoFilters();
                            foreach (var item in filters)
                            {
                                if (item.LastRun == null || item.LastRun.Value.AddDays(1) < DateTime.Now)
                                {
                                    var users = NotificationGroups.GetUsersOfAutoFilter(item);
                                    try
                                    {
                                        Task.Run(() => Snoopi.core.FcmService.SendTemplateToMany(item.Name, item.MessageTemplate, users)).Wait();
                                    }
                                    catch (Exception ex)
                                    {
                                        using (System.IO.StreamWriter sw = System.IO.File.AppendText(AppDomain.CurrentDomain.BaseDirectory + @"\Output\push-log.txt"))
                                        {
                                            sw.WriteLine(@" ------------" + DateTime.Now + "--------------------" + '\n' + "Exception  " + ex.Message + " CallStack : " + ex.StackTrace);
                                        }
                                    }
                                    item.LastRun = DateTime.Now;
                                    item.Save();
                                }
                            }

                            jsonWriter.WritePropertyName(@"success");
                            jsonWriter.WriteValue(true);
                        }
                        catch (System.Exception ex)
                        {
                            //RespondError(Response, HttpStatusCode.BadRequest, ex.ToString());
                            jsonWriter.WritePropertyName(@"error");
                            jsonWriter.WriteValue(@"unknown");
                            jsonWriter.WritePropertyName(@"description");
                            jsonWriter.WriteValue(ex.ToString());
                        }
                        jsonWriter.WriteEndObject();
                    }
                }
            }
            else if (PathParams[0] == @"rate_supplier")
            {
                using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                {
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                    {
                        jsonWriter.WriteStartObject();
                        try
                        {
                            Query qry = new Query(Order.TableSchema);
                            qry.Where(Order.Columns.IsSendRateSupplier, WhereComparision.EqualsTo, false);
                            qry.AddWhere(Order.Columns.SuppliedDate, WhereComparision.LessThanOrEqual, DateTime.UtcNow.AddHours(-Settings.GetSettingInt32(Settings.Keys.RATE_SUPPLIER_AFTER_ORDER_HOUR, 24)));

                            OrderCollection orderCollection = OrderCollection.FetchByQuery(qry);

                            Query.New <Order>().Where(Order.Columns.IsSendRateSupplier, WhereComparision.EqualsTo, false)
                            .AddWhere(Order.Columns.SuppliedDate, WhereComparision.LessThanOrEqual, DateTime.UtcNow.AddHours(-Settings.GetSettingInt32(Settings.Keys.RATE_SUPPLIER_AFTER_ORDER_HOUR, 24)))
                            .Update(Order.Columns.IsSendRateSupplier, true)
                            .Execute();

                            foreach (Order item in orderCollection)
                            {
                                var         bid      = Bid.FetchByID(item.BidId);
                                AppSupplier supplier = AppSupplier.FetchByID(item.SupplierId);
                                Notification.SendNotificationAppUserRateSupplier(Snoopi.web.Localization.PushStrings.GetText("RateSupplier"), item.AppUserId, item.SupplierId.Value, supplier.BusinessName, item.BidId);
                                item.IsSendRateSupplier = true;
                                item.Save();
                            }

                            jsonWriter.WritePropertyName(@"success");
                            jsonWriter.WriteValue(true);
                        }
                        catch (System.Exception ex)
                        {
                            //RespondError(Response, HttpStatusCode.BadRequest, ex.ToString());
                            jsonWriter.WritePropertyName(@"error");
                            jsonWriter.WriteValue(@"unknown");
                            jsonWriter.WritePropertyName(@"description");
                            jsonWriter.WriteValue(ex.ToString());
                        }
                        jsonWriter.WriteEndObject();
                    }
                }
            }
            else if (PathParams[0] == @"test_rate_supplier")
            {
                Notification.SendNotificationAppUserRateSupplier(Snoopi.web.Localization.PushStrings.GetText("RateSupplier"), 18283, 387, "PetBool", 2345);
            }
            else
            {
                using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                {
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                    {
                        jsonWriter.WriteStartObject();
                        jsonWriter.WritePropertyName(@"error");
                        jsonWriter.WriteValue(@"unknown");
                        jsonWriter.WriteEndObject();
                    }
                }
            }
        }
        public static List <OrderUI> GetAllAppUserOrders(Int64 AppUserId = 0, DateTime from = new DateTime(), DateTime to = new DateTime(), string SearchBid = "", int PageSize = 0, int CurrentPageIndex = 0)
        {
            Query q = new Query(Order.TableSchema);

            q.Join(JoinType.InnerJoin, Order.TableSchema, Order.Columns.BidId, Order.TableSchema.SchemaName,
                   Bid.TableSchema, Bid.Columns.BidId, Bid.TableSchema.SchemaName);
            q.Join(JoinType.LeftJoin, Order.TableSchema, Order.Columns.DonationId, Order.TableSchema.SchemaName,
                   Donation.TableSchema, Donation.Columns.DonationId, Donation.TableSchema.SchemaName);
            q.Join(JoinType.InnerJoin, Order.TableSchema, Order.Columns.SupplierId, Order.TableSchema.SchemaName,
                   AppSupplier.TableSchema, AppSupplier.Columns.SupplierId, AppSupplier.TableSchema.SchemaName);
            q.Join(JoinType.LeftJoin, Order.TableSchema, Order.Columns.CampaignId, Order.TableSchema.SchemaName,
                   Campaign.TableSchema, Campaign.Columns.CampaignId, Campaign.TableSchema.SchemaName);

            q.OrderBy(Order.TableSchema.SchemaName, Order.Columns.CreateDate, SortDirection.DESC);
            q.Select(Order.TableSchema.SchemaName, Order.Columns.OrderId, Order.Columns.OrderId, true);
            q.AddSelect(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.BusinessName, AppSupplier.Columns.BusinessName);
            q.AddSelect(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.SupplierId, AppSupplier.Columns.SupplierId);
            q.AddSelect(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.Precent, AppSupplier.Columns.Precent);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.CreateDate, Order.Columns.CreateDate);
            q.AddSelect(Bid.TableSchema.SchemaName, Bid.Columns.BidId, Bid.Columns.BidId);
            q.AddSelect(Bid.TableSchema.SchemaName, Bid.Columns.StartDate, Bid.Columns.StartDate);
            q.AddSelect(Bid.TableSchema.SchemaName, Bid.Columns.EndDate, Bid.Columns.EndDate);
            q.AddSelect(Donation.TableSchema.SchemaName, Donation.Columns.DonationPrice, Donation.Columns.DonationPrice);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.TotalPrice, Order.Columns.TotalPrice);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.Gifts, Order.Columns.Gifts);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.TotalPrice, Order.Columns.TotalPrice);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.PriceAfterDiscount, Order.Columns.PriceAfterDiscount);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.PrecentDiscount, Order.Columns.PrecentDiscount);
            q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.IsSendRecived, Order.Columns.IsSendRecived);
            //q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.TransactionResponseCode, Order.Columns.TransactionResponseCode);
            //q.AddSelect(Order.TableSchema.SchemaName, Order.Columns.TransactionStatus, Order.Columns.TransactionStatus);
            q.AddSelect(Campaign.TableSchema.SchemaName, Campaign.Columns.CampaignName, Campaign.Columns.CampaignName);
            q.Where(Order.TableSchema.SchemaName, Order.Columns.AppUserId, WhereComparision.EqualsTo, AppUserId);
            q.AddWhere(Order.TableSchema.SchemaName, Order.Columns.UserPaySupplierStatus, WhereComparision.EqualsTo, UserPaymentStatus.Payed);
            if (from != DateTime.MinValue)
            {
                q.AddWhere(Order.TableSchema.SchemaName, Order.Columns.CreateDate, WhereComparision.GreaterThanOrEqual, from);
            }
            if (to != DateTime.MinValue)
            {
                q.AddWhere(Order.TableSchema.SchemaName, Order.Columns.CreateDate, WhereComparision.LessThanOrEqual, to);
            }
            if (SearchBid != "")
            {
                q.AddWhere(Order.TableSchema.SchemaName, Order.Columns.BidId, WhereComparision.Like, SearchBid);
            }
            if (PageSize > 0)
            {
                q.LimitRows(PageSize).OffsetRows(PageSize * CurrentPageIndex);
            }

            List <OrderUI> LstOrder = new List <OrderUI>();

            using (DataReaderBase reader = q.ExecuteReader())
            {
                while (reader.Read())
                {
                    OrderUI orderUI = new OrderUI();
                    orderUI.SupplierName       = (reader[AppSupplier.Columns.BusinessName] != null ? reader[AppSupplier.Columns.BusinessName].ToString() : "");
                    orderUI.SupplierId         = (reader[AppSupplier.Columns.SupplierId] != null ? Int64.Parse(reader[AppSupplier.Columns.SupplierId].ToString()) : 0);
                    orderUI.OrderId            = (reader[Order.Columns.OrderId] != null ? Int64.Parse(reader[Order.Columns.OrderId].ToString()) : 0);
                    orderUI.OrderDate          = (reader[Order.Columns.CreateDate] != null ? DateTime.Parse(reader[Order.Columns.CreateDate].ToString()).ToLocalTime() : DateTime.MinValue);
                    orderUI.BidId              = (reader[Bid.Columns.BidId] != null ? Int64.Parse(reader[Bid.Columns.BidId].ToString()) : 0);
                    orderUI.BidEndDate         = (reader[Bid.Columns.EndDate] != null ? DateTime.Parse(reader[Bid.Columns.EndDate].ToString()).ToLocalTime() : DateTime.MinValue);
                    orderUI.DonationPrice      = ((reader[Donation.Columns.DonationPrice] is DBNull) ? 0 : Convert.ToDecimal(reader[Donation.Columns.DonationPrice]));
                    orderUI.TotalPrice         = (reader[Order.Columns.TotalPrice] != null ? decimal.Parse(reader[Order.Columns.TotalPrice].ToString()) : 0);
                    orderUI.PriceAfterDiscount = (reader[Order.Columns.PriceAfterDiscount] != null ? decimal.Parse(reader[Order.Columns.PriceAfterDiscount].ToString()) : 0);
                    orderUI.Precent            = (reader[AppSupplier.Columns.Precent] != null ? Int32.Parse(reader[AppSupplier.Columns.Precent].ToString()) : 0);
                    orderUI.PaymentForSupplier = orderUI.TotalPrice * ((100m - orderUI.Precent) / 100);
                    orderUI.PrecentDiscount    = (reader[Order.Columns.PrecentDiscount] != null ? Int32.Parse(reader[Order.Columns.PrecentDiscount].ToString()) : 0);
                    orderUI.IsSendReceived     = (reader[Order.Columns.IsSendRecived] != null) ? Convert.ToBoolean(reader[Order.Columns.IsSendRecived]) : false;
                    // orderUI.TransactionResponseCode = (reader[Order.Columns.TransactionResponseCode] != null ? reader[Order.Columns.TransactionResponseCode].ToString() : "");
                    // orderUI.TransactionStatus = (OrderStatus)Enum.Parse(typeof(OrderStatus), reader[Order.Columns.TransactionStatus].ToString());
                    orderUI.Gift         = (reader[Order.Columns.Gifts] != null ? reader[Order.Columns.Gifts].ToString() : "");
                    orderUI.CampaignName = (reader[Campaign.Columns.CampaignName] != null ? reader[Campaign.Columns.CampaignName].ToString() : "");
                    orderUI.LstProduct   = BidController.GetProductsByBid(orderUI.BidId);
                    LstOrder.Add(orderUI);
                }
            }
            return(LstOrder);
        }
Example #5
0
        protected void btnExportForCRM_Click(object sender, EventArgs e)
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add(new System.Data.DataColumn(OrdersStrings.GetText(@"ActionType"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(OrdersStrings.GetText(@"SupplierId"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(OrdersStrings.GetText(@"SupplierName"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"Phone"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(SuppliersStrings.GetText(@"Email"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(OrdersStrings.GetText(@"BidId"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(OrdersStrings.GetText(@"Products"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(OrdersStrings.GetText(@"TotalPrice"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(OrdersStrings.GetText(@"PaymentForSupplier"), typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn(OrdersStrings.GetText(@"OrderDate"), typeof(string)));


            DateTime from, to = new DateTime();

            if (DateTime.TryParse(datepickerFrom.Value.ToString(), out from))
            {
                TimeSpan tsFrom = new TimeSpan(TimeSelectorFrom.Hour, TimeSelectorFrom.Minute, 0);
                from = from.Date + tsFrom;
            }
            if (DateTime.TryParse(datepickerTo.Value.ToString(), out to))
            {
                TimeSpan tsTo = new TimeSpan(TimeSelectorTo.Hour, TimeSelectorTo.Minute, 0);
                to = to.Date + tsTo;
            }
            List <Int64>   SuppliersIdList      = FillSupplierList();
            List <bool>    IsReceivedSendDate   = FillIsSendReceived();
            List <int>     StatusIdList         = FillStatusList();
            List <int>     StatusPayementIdList = FillPayementStatusList();
            string         SearchBid            = "%" + txtSearchBid.Text.Trim() + "%";
            List <OrderUI> orders = OrderController.GetAllOrders(from, to, SuppliersIdList, IsReceivedSendDate, StatusIdList, StatusPayementIdList, SearchBid);

            foreach (OrderUI order in orders)
            {
                var supplier            = SupplierController.GetSupplierUI(order.SupplierId);
                System.Data.DataRow row = dt.NewRow();
                row[0] = "רכישה";
                row[1] = order.SupplierId;
                row[2] = order.SupplierName;
                row[3] = supplier == null?"": "=\"" + supplier.Phone + "\"";
                row[4] = supplier == null ? "" : supplier.Email;
                row[5] = order.BidId;
                row[6] = GetStringProduct(BidController.GetProductsByBid(order.BidId));
                row[7] = order.TotalPrice;
                row[8] = order.PaymentForSupplier;
                row[9] = order.OrderDate;


                dt.Rows.Add(row);
            }
            System.Data.DataRow sumRow = dt.NewRow();
            dt.Rows.Add(sumRow);

            SpreadsheetWriter ex = SpreadsheetWriter.FromDataTable(dt, false, true);

            Response.Clear();
            Response.AddHeader(@"content-disposition", @"attachment;filename=OrdersExportFoCRM_" + DateTime.UtcNow.ToString(@"yyyy_MM_dd_HH_mm_ss") + "." + ex.FileExtension);
            Response.Charset         = @"UTF-8";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = ex.FileContentType;
            Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());
            Response.Write(ex.ToString());
            Response.End();
        }
        public override void Get(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);

            try
            {
                //Int64 bid_id = (Request.QueryString["bid_id"] != null ? Int64.Parse(Request.QueryString["bid_id"].ToString()) : 0 );

                Response.ContentType = @"application/json";
                using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                {
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                    {
                        Int64 bid_id = 0;
                        Int64 AppUserId;
                        Int64 TempAppUserId = 0;
                        if (IsAuthorizedRequest(Request, Response, false, out AppUserId))
                        {
                            //the last bid of the app user that ended
                            Bid b = Bid.FetchByAppUserId(AppUserId);
                            if (b != null)
                            {
                                //if the bid isn't closed (there arn't any orders for this bid)
                                Order o = Order.FetchByBidId(b.BidId);
                                //if (o == null)
                                if (o == null || o.UserPaySupplierStatus == UserPaymentStatus.NotPayed)
                                {
                                    bid_id = b.BidId;
                                }
                            }
                        }
                        else
                        {
                            TempAppUserId = Request["temp_app_user_id"] != null?Convert.ToInt64(Request["temp_app_user_id"]) : 0;

                            if (TempAppUserId != 0)
                            {
                                //the last bid of the temp app user that ended
                                Bid b = Bid.FetchByTempAppUserId(TempAppUserId);
                                if (b != null)
                                {
                                    //if the bid isn't closed (there arn't any orders for this bid)
                                    Order o = Order.FetchByBidId(b.BidId);
                                    //if (o == null)
                                    if (o == null || o.UserPaySupplierStatus == UserPaymentStatus.NotPayed)
                                    {
                                        bid_id = b.BidId;
                                    }
                                }
                            }
                        }

                        Bid bid = Bid.FetchByID(bid_id);
                        if (bid_id == 0 || bid == null)
                        {
                            jsonWriter.WriteStartObject();
                            jsonWriter.WriteEndObject();
                        }
                        else
                        {
                            DateTime DateExpiryOffers = bid.EndDate.AddHours(Convert.ToDouble(Settings.GetSetting(Settings.Keys.EXPIRY_OFFER_TIME_HOURS)));

                            List <OfferUI> lstOfferUI = (bid_id != 0 && bid != null && DateTime.UtcNow < DateExpiryOffers ? OfferController.GetAllOfferByBidId(bid_id) : new List <OfferUI>());
                            jsonWriter.WriteStartObject();

                            jsonWriter.WritePropertyName(@"bid_id");
                            jsonWriter.WriteValue(bid_id);

                            jsonWriter.WritePropertyName(@"products");
                            jsonWriter.WriteStartArray();
                            List <BidProductUI> products = BidController.GetProductsByBid(bid_id);
                            foreach (BidProductUI item in products)
                            {
                                jsonWriter.WriteStartObject();

                                jsonWriter.WritePropertyName(@"product_id");
                                jsonWriter.WriteValue(item.ProductId);
                                jsonWriter.WritePropertyName(@"order_amount");
                                jsonWriter.WriteValue(item.Amount);
                                jsonWriter.WritePropertyName(@"product_name");
                                jsonWriter.WriteValue(item.ProductName);
                                jsonWriter.WritePropertyName(@"product_image");
                                jsonWriter.WriteValue(item.ProductImage);

                                jsonWriter.WriteEndObject();
                            }

                            jsonWriter.WriteEndArray();

                            jsonWriter.WritePropertyName(@"offers");
                            jsonWriter.WriteStartArray();

                            foreach (OfferUI item in lstOfferUI)
                            {
                                jsonWriter.WriteStartObject();

                                jsonWriter.WritePropertyName(@"offer_id");
                                jsonWriter.WriteValue(item.OfferId);
                                jsonWriter.WritePropertyName(@"supplier_id");
                                jsonWriter.WriteValue(item.SupplierId);
                                jsonWriter.WritePropertyName(@"mastercard_code");
                                if (item.MastercardCode == "")
                                {
                                    jsonWriter.WriteValue((-1).ToString());
                                }
                                else
                                {
                                    jsonWriter.WriteValue(item.MastercardCode);
                                }
                                jsonWriter.WritePropertyName(@"avg_rate");
                                jsonWriter.WriteValue(item.AvgRate);
                                jsonWriter.WritePropertyName(@"supplier_name");
                                jsonWriter.WriteValue(item.SupplierName);
                                jsonWriter.WritePropertyName(@"total_price");
                                jsonWriter.WriteValue(item.TotalPrice);
                                jsonWriter.WritePropertyName(@"gift");
                                jsonWriter.WriteValue(item.Gift);

                                jsonWriter.WriteEndObject();
                            }

                            jsonWriter.WriteEndArray();

                            jsonWriter.WriteEndObject();
                        }
                    }
                }
            }
            catch (Exception) { }
        }