示例#1
0
        public static Int64 CreateBidService(Int64 AppUserId, Int64 TempAppUserId, Int64 ServiceId, string CustomerComment)
        {
            BidService NewBid  = new BidService();
            BidService HelpBid = GetActiveBidServiceByAppOrTempUserId(AppUserId, TempAppUserId);
            Int64      CityId  = 0;

            Geometry.Point Location = null;
            if (HelpBid != null)
            {
                return(0);
            }
            if (AppUserId != 0)
            {
                AppUser a = AppUser.FetchByID(AppUserId);
                NewBid.AppUserId = AppUserId;;
                CityId           = a.CityId;
                Location         = a.AddressLocation;
            }
            else if (TempAppUserId != 0)
            {
                TempAppUser t = TempAppUser.FetchByID(TempAppUserId);
                NewBid.TempAppUserId = TempAppUserId;
                CityId   = t.CityId;
                Location = t.Location;
            }
            NewBid.ServiceId      = ServiceId;
            NewBid.StartDate      = DateTime.UtcNow;
            NewBid.ServiceComment = CustomerComment;
            NewBid.EndDate        = DateTime.UtcNow.AddHours(Convert.ToDouble(Settings.GetSettingDecimal(Settings.Keys.END_BID_TIME_MIN, 15)));
            NewBid.Save();

            //send push to suppliers
            SendPushToSuppliers(NewBid.BidId, ServiceId, CityId, Location);
            return(NewBid.BidId);
        }
        public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);

            JObject inputData = null;

            try
            {
                using (StreamReader reader = new StreamReader(Request.InputStream))
                {
                    using (JsonTextReader jsonReader = new JsonTextReader(reader))
                    {
                        inputData = JObject.Load(jsonReader);
                    }
                }
            }
            catch
            {
                RespondBadRequest(Response);
            }

            string device_udid = inputData.Value <string>(@"device_udid") ?? "";
            Int64  city_id     = inputData.Value <Int64>(@"city_id") != null?inputData.Value <Int64>(@"city_id") : 0;

            Response.ContentType = @"application/json";

            using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
            {
                using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                {
                    TempAppUser temp = new TempAppUser();
                    temp.CityId     = city_id;
                    temp.DeviceUdid = device_udid;
                    City c = City.FetchByID(city_id);
                    if (c != null)
                    {
                        var locationService = new GoogleLocationService();
                        var point           = locationService.GetLatLongFromAddress(c.CityName);
                        temp.Location = (point != null ? new dg.Sql.Geometry.Point(point.Latitude, point.Longitude) : new dg.Sql.Geometry.Point(0, 0));
                    }
                    temp.Save();

                    jsonWriter.WriteStartObject();

                    jsonWriter.WritePropertyName(@"temp_app_user_id");
                    jsonWriter.WriteValue(temp.TempAppUserId);

                    jsonWriter.WriteEndObject();
                }
            }
        }
示例#3
0
        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 AppUserId;
                        Int64 tempAppUserId = 0;
                        IsAuthorizedRequest(Request, Response, false, out AppUserId);
                        AppUser user = null;
                        if (AppUserId != 0)
                        {
                            user = AppUser.FetchByID(AppUserId);
                            bool _locked = user != null ? user.IsLocked : true;
                            if (_locked)
                            {
                                RespondError(Response, HttpStatusCode.BadRequest, @"appuser-locked");
                                return;
                            }
                        }
                        TempAppUser tempUser = null;
                        tempAppUserId = Request.QueryString["temp_app_user_id"] != null?Int64.Parse(Request.QueryString["temp_app_user_id"].ToString()) : 0;

                        if (tempAppUserId > 0)
                        {
                            tempUser = TempAppUser.FetchByID(tempAppUserId);
                        }

                        int service_id = 0;
                        service_id = Request.QueryString["service_id"] != null?int.Parse(Request.QueryString["service_id"].ToString()) : 0;

                        long cityId;
                        cityId = Request.QueryString["city_id"] != null?Int64.Parse(Request.QueryString["city_id"].ToString()) : 0;

                        if (cityId <= 0)
                        {
                            cityId = user != null ? user.CityId : tempUser.CityId;
                        }

                        string cityName = Request.QueryString["city_name"];

                        var promotedSuppliers = SupplierPromotedController.GetSuppliersPromotedOfCity(cityId, service_id, 5);

                        Geometry.Point location = null;
                        if (!String.IsNullOrWhiteSpace(cityName))
                        {
                            var locationService = new GoogleLocationService();
                            var point           = locationService.GetLatLongFromAddress(cityName);
                            location = (point != null ? new dg.Sql.Geometry.Point(point.Latitude, point.Longitude) : new dg.Sql.Geometry.Point(0, 0));
                        }

                        if (location == null)
                        {
                            if (user != null)
                            {
                                location = user.AddressLocation;
                            }
                            else
                            {
                                location = tempUser.Location;
                            }
                        }
                        var regularSuppliers = ServiceController.GetServiceSuppliersByDistance(service_id, cityId, location, promotedSuppliers);

                        int index = 1;

                        jsonWriter.WriteStartObject();
                        jsonWriter.WritePropertyName(@"promoted_suppliers");
                        jsonWriter.WriteStartArray();
                        foreach (var item in promotedSuppliers)
                        {
                            jsonWriter.WriteStartObject();

                            jsonWriter.WritePropertyName(@"supplier_id");
                            jsonWriter.WriteValue(item.SupplierId);
                            jsonWriter.WritePropertyName(@"supplier_name");
                            jsonWriter.WriteValue(item.BusinessName ?? "");
                            jsonWriter.WritePropertyName(@"phone");
                            jsonWriter.WriteValue(item.Phone ?? "");
                            jsonWriter.WritePropertyName(@"city");
                            jsonWriter.WriteValue(item.CityName ?? "");
                            jsonWriter.WritePropertyName(@"street");
                            jsonWriter.WriteValue(item.Street ?? "");
                            jsonWriter.WritePropertyName(@"house_num");
                            jsonWriter.WriteValue(item.HouseNum ?? "");
                            jsonWriter.WritePropertyName(@"avg_rate");
                            jsonWriter.WriteValue(item.AvgRate);
                            jsonWriter.WritePropertyName(@"index");
                            jsonWriter.WriteValue(index++);
                            jsonWriter.WritePropertyName(@"description");
                            jsonWriter.WriteValue(item.Description);
                            jsonWriter.WritePropertyName(@"image");
                            jsonWriter.WriteValue(item.ProfileImage);
                            jsonWriter.WritePropertyName(@"comments_number");
                            jsonWriter.WriteValue(item.NumberOfComments);
                            jsonWriter.WriteEndObject();
                        }
                        jsonWriter.WriteEndArray();

                        jsonWriter.WritePropertyName(@"suppliers");
                        jsonWriter.WriteStartArray();
                        foreach (var item in regularSuppliers)
                        {
                            jsonWriter.WriteStartObject();

                            jsonWriter.WritePropertyName(@"supplier_id");
                            jsonWriter.WriteValue(item.SupplierId);
                            jsonWriter.WritePropertyName(@"supplier_name");
                            jsonWriter.WriteValue(item.BusinessName ?? "");
                            jsonWriter.WritePropertyName(@"phone");
                            jsonWriter.WriteValue(item.Phone ?? "");
                            jsonWriter.WritePropertyName(@"city");
                            jsonWriter.WriteValue(item.CityName ?? "");
                            jsonWriter.WritePropertyName(@"street");
                            jsonWriter.WriteValue(item.Street ?? "");
                            jsonWriter.WritePropertyName(@"house_num");
                            jsonWriter.WriteValue(item.HouseNum ?? "");
                            jsonWriter.WritePropertyName(@"avg_rate");
                            jsonWriter.WriteValue(item.AvgRate);
                            jsonWriter.WritePropertyName(@"index");
                            jsonWriter.WriteValue(index++);
                            jsonWriter.WritePropertyName(@"description");
                            jsonWriter.WriteValue(item.Description);
                            jsonWriter.WritePropertyName(@"image");
                            jsonWriter.WriteValue(item.ProfileImage);
                            jsonWriter.WritePropertyName(@"comments_number");
                            jsonWriter.WriteValue(item.NumberOfComments);
                            jsonWriter.WriteEndObject();
                        }
                        jsonWriter.WriteEndArray();
                        jsonWriter.WriteEndObject();
                    }
                }
            }
            catch (Exception) { }
        }
        public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);

            JObject inputData = null;

            try
            {
                using (StreamReader reader = new StreamReader(Request.InputStream))
                {
                    using (JsonTextReader jsonReader = new JsonTextReader(reader))
                    {
                        inputData = JObject.Load(jsonReader);
                    }
                }
            }
            catch
            {
                RespondBadRequest(Response);
            }

            Response.ContentType = @"application/json";

            JToken jt;
            JArray products       = null;
            var    productsOffers = new List <BidProductUI>();
            Dictionary <Int64, int> lstProduct = new Dictionary <Int64, int>();

            Int64 AppUserId;

            IsAuthorizedRequest(Request, Response, false, out AppUserId);

            Int64 TempAppUserId = 0;

            if (inputData.TryGetValue(@"temp_app_user_id", out jt))
            {
                TempAppUserId = jt.Value <Int64>();
            }
            if (AppUserId == 0 && TempAppUserId == 0)
            {
                RespondError(Response, HttpStatusCode.Forbidden, @"authorization-error");
                return;
            }
            var user     = AppUser.FetchByID(AppUserId);
            var tempUser = TempAppUser.FetchByID(TempAppUserId);

            if (user == null && tempUser == null)
            {
                RespondError(Response, HttpStatusCode.Forbidden, @"authorization-error");
                return;
            }

            long cityId = 0;

            if (user != null)
            {
                bool _locked = user.IsLocked;
                if (_locked)
                {
                    RespondError(Response, HttpStatusCode.BadRequest, @"appuser-locked");
                    return;
                }
                cityId = user.CityId;
            }
            else if (tempUser != null)
            {
                cityId = tempUser.CityId;
            }

            if (inputData.TryGetValue(@"products", out jt))
            {
                products = jt.Value <JArray>();
            }
            foreach (JObject obj in products.Children <JObject>())
            {
                Int64 product_id = 0;
                int   amount     = 1;
                if (obj.TryGetValue(@"product_id", out jt))
                {
                    product_id = jt.Value <Int64>();
                }
                if (obj.TryGetValue(@"amount", out jt))
                {
                    amount = jt.Value <int>();
                }
                lstProduct.Add(product_id, amount);
            }

            var lstOfferUI = OfferController.GetAllOfferByProductIds(lstProduct, cityId);

            Response.ContentType = @"application/json";
            using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
            {
                using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                {
                    if (IsAuthorizedRequest(Request, Response, false, out AppUserId))
                    {
                        jsonWriter.WriteStartObject();
                        jsonWriter.WritePropertyName(@"products");
                        jsonWriter.WriteStartArray();
                        foreach (BidProductUI item in productsOffers) /* TODO: should be deleted*/
                        {
                            jsonWriter.WriteStartObject();

                            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();
                    }
                }
            }
        }
示例#5
0
        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 AppUserId;
                        Int64 bid_id = 0;
                        IsAuthorizedRequest(Request, Response, false, out AppUserId);
                        Int64          TempAppUserId = (Request.QueryString["temp_app_user_id"] != null ? Convert.ToInt64(Request.QueryString["temp_app_user_id"]) : 0);
                        Geometry.Point point         = new Geometry.Point();
                        if (TempAppUserId != 0)
                        {
                            TempAppUser temp = TempAppUser.FetchByID(TempAppUserId);
                            point = (temp != null ? temp.Location : new Geometry.Point(0, 0));
                            //Bid b = Bid.FetchByTempAppUserId(TempAppUserId);
                            BidService bService = BidService.FetchByTempAppUserId(TempAppUserId);
                            if (bService != null)
                            {
                                bid_id = bService.BidId;
                            }
                        }
                        else if (AppUserId != 0)
                        {
                            AppUser user = AppUser.FetchByID(AppUserId);
                            point = (user != null ? user.AddressLocation : new Geometry.Point(0, 0));
                            //Bid b = Bid.FetchByAppUserId(AppUserId);
                            BidService bService = BidService.FetchByAppUserId(AppUserId);
                            if (bService != null)
                            {
                                bid_id = bService.BidId;
                            }
                        }

                        BidService bidService = BidService.FetchByID(bid_id);

                        List <OfferServiceUI> lstOfferUI = bid_id != 0 ? OfferServiceController.GetAllOfferByBidId(bid_id, bidService.EndDate, point) :  new List <OfferServiceUI>();
                        jsonWriter.WriteStartObject();

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

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

                            jsonWriter.WritePropertyName(@"offer_id");
                            jsonWriter.WriteValue(item.OfferId);
                            jsonWriter.WritePropertyName(@"supplier_id");
                            jsonWriter.WriteValue(item.SupplierId);
                            jsonWriter.WritePropertyName(@"supplier_name");
                            jsonWriter.WriteValue(item.SupplierName);
                            jsonWriter.WritePropertyName(@"price");
                            jsonWriter.WriteValue(item.Price);
                            jsonWriter.WritePropertyName(@"address");
                            jsonWriter.WriteValue(item.Address);
                            jsonWriter.WritePropertyName(@"phone");
                            jsonWriter.WriteValue(item.Phone);

                            jsonWriter.WriteEndObject();
                        }

                        jsonWriter.WriteEndArray();

                        jsonWriter.WriteEndObject();
                    }
                }
            }
            catch (Exception) { }
        }
示例#6
0
        public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);
            JObject inputData = null;

            try
            {
                using (StreamReader reader = new StreamReader(Request.InputStream))
                {
                    using (JsonTextReader jsonReader = new JsonTextReader(reader))
                    {
                        inputData = JObject.Load(jsonReader);
                    }
                }
            }
            catch
            {
                RespondBadRequest(Response);
            }

            JToken jt;
            Int64  AppUserId;

            IsAuthorizedRequest(Request, Response, false, out AppUserId);

            Int64 TempAppUserId = 0;

            if (inputData.TryGetValue(@"temp_app_user_id", out jt))
            {
                TempAppUserId = jt.Value <Int64>();
            }
            if (AppUserId == 0 && TempAppUserId == 0)
            {
                RespondError(Response, HttpStatusCode.Forbidden, @"authorization-error");
                return;
            }
            var user     = AppUser.FetchByID(AppUserId);
            var tempUser = TempAppUser.FetchByID(TempAppUserId);

            if (user == null && tempUser == null)
            {
                RespondError(Response, HttpStatusCode.Forbidden, @"authorization-error");
                return;
            }

            long cityId = 0;

            if (user != null)
            {
                bool _locked = user.IsLocked;
                if (_locked)
                {
                    RespondError(Response, HttpStatusCode.BadRequest, @"appuser-locked");
                    return;
                }
                cityId = user.CityId;
            }
            else if (tempUser != null)
            {
                cityId = tempUser.CityId;
            }

            Response.ContentType = @"application/json";

            try
            {
                //Int64 order_id = 0;
                JArray  products   = null;
                Int64   supplierId = 0;
                decimal totalPrice = 0;
                var     lstProduct = new Dictionary <Int64, int>();

                if (inputData.TryGetValue(@"products", out jt))
                {
                    products = jt.Value <JArray>();
                }
                if (inputData.TryGetValue(@"supplier_id", out jt))
                {
                    supplierId = jt.Value <Int64>();
                }
                if (inputData.TryGetValue(@"total_price", out jt) && jt != null)
                {
                    totalPrice = jt.Value <decimal>();
                }

                foreach (JObject obj in products.Children <JObject>())
                {
                    Int64 product_id = 0;
                    int   amount     = 1;
                    if (obj.TryGetValue(@"product_id", out jt))
                    {
                        product_id = jt.Value <Int64>();
                    }
                    if (obj.TryGetValue(@"amount", out jt))
                    {
                        amount = jt.Value <int>();
                    }
                    lstProduct.Add(product_id, amount);
                }

                int cartId = CartController.CreateCart(AppUserId, TempAppUserId, supplierId, totalPrice, lstProduct);
                using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                {
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                    {
                        jsonWriter.WriteStartObject();
                        jsonWriter.WritePropertyName(@"cart_id");
                        jsonWriter.WriteValue(cartId);
                        jsonWriter.WriteEndObject();
                    }
                }
            }

            catch (Exception)
            {
                RespondError(Response, HttpStatusCode.InternalServerError, @"db-error");
            }
        }