Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
6.4 kB
12
Indexable
Never
//Add data and images in firebase database and storage
        public async Task<bool> AddListings(string propname, string propdesc, string propstock,
            FileResult mainimg, FileResult img1, FileResult img2, FileResult img3, FileResult img4,
            FileResult img5, FileResult img6, string propcategory, string propstatus, string rentPrice, string propunitoftime, string propdetails,
            string durationunitoftime)
        //MediaFile img1, MediaFile img2, string propCategory, string propStatus,
        //MediaFile img3, MediaFile img4, MediaFile img5, MediaFile img6
        {
            try
            {
                var evaluateProperty = (await client
                .Child($"Lessors/{lessorkey}/Properties")
                .OnceAsync<MyListings>()).FirstOrDefault
                (a => a.Object.PropertyName == propname);
                if (evaluateProperty == null)
                {
                    //Save Listing images
                    var _mainimg = await UploadImage(await mainimg.OpenReadAsync(), _propname, $"{propname}_mainimg.png");
                    var _img1 = await UploadImage(await img1.OpenReadAsync(), _propname, $"{propname}_img1.png");
                    var _img2 = await UploadImage(await img2.OpenReadAsync(), _propname, $"{propname}_img2.png");
                    var _img3 = await UploadImage(await img3.OpenReadAsync(), _propname, $"{propname}_img3.png");
                    var _img4 = await UploadImage(await img4.OpenReadAsync(), _propname, $"{propname}_img4.png");
                    var _img5 = await UploadImage(await img5.OpenReadAsync(), _propname, $"{propname}_img5.png");
                    var _img6 = await UploadImage(await img6.OpenReadAsync(), _propname, $"{propname}_img6.png");
                    //Save Listing info.
                    var lessors = new MyListings()
                    {
                        PropertyName = propname,
                        PropertyDescription = propdesc,
                        PropertyStock = propstock,
                        PropMainImage = _mainimg,
                        PropertyCategory = propcategory,
                        PropertyStatus = propstatus,
                        Prop_RentPrice = rentPrice,
                        Prop_RentUnitOfTime = propunitoftime,
                        PropertyDetails = propdetails,
                        Prop_RentDuration = durationunitoftime,
                        PropImg_1 = _img1,
                        PropImg_2 = _img2,
                        PropImg_3 = _img3,
                        PropImg_4 = _img4,
                        PropImg_5 = _img5,
                        PropImg_6 = _img6,
                        PublishStatus = "0"
                    };
                    await client
                        .Child($"Lessors/{lessorkey}/Properties")
                        .PostAsync(lessors);

                    var getPropertyKey = (await client
                        .Child($"Lessors/{lessorkey}/Properties")
                        .OnceAsync<MyListings>()).FirstOrDefault
                        (a => a.Object.PropertyName == propname);
                    if (getPropertyKey != null)
                    {
                        var b = getPropertyKey.Key;
                        //**********Main image
                        var imgmain = new MyListings()
                        {
                            ImgUrl = _mainimg,
                        };
                        await client
                            .Child($"Lessors/{lessorkey}/Properties/{b}/CarouselImages/{propname}")
                            .PostAsync(imgmain);
                        //**********1 image
                        var img_1 = new MyListings()
                        {
                            ImgUrl = _img1,
                        };
                        await client
                            .Child($"Lessors/{lessorkey}/Properties/{b}/CarouselImages/{propname}")
                            .PostAsync(img_1);

                        //**********2 image
                        var img_2 = new MyListings()
                        {
                            ImgUrl = _img2,
                        };
                        await client
                            .Child($"Lessors/{lessorkey}/Properties/{b}/CarouselImages/{propname}")
                            .PostAsync(img_2);

                        //**********3 image
                        var img_3 = new MyListings()
                        {
                            ImgUrl = _img3,
                        };
                        await client
                            .Child($"Lessors/{lessorkey}/Properties/{b}/CarouselImages/{propname}")
                            .PostAsync(img_3);
                        //**********4 image
                        var img_4 = new MyListings()
                        {
                            ImgUrl = _img4,
                        };
                        await client
                            .Child($"Lessors/{lessorkey}/Properties/{b}/CarouselImages/{propname}")
                            .PostAsync(img_4);
                        //**********5 image
                        var img_5 = new MyListings()
                        {
                            ImgUrl = _img5,
                        };
                        await client
                            .Child($"Lessors/{lessorkey}/Properties/{b}/CarouselImages/{propname}")
                            .PostAsync(img_5);
                        //**********6 image
                        var img_6 = new MyListings()
                        {
                            ImgUrl = _img6,
                        };
                        await client
                            .Child($"Lessors/{lessorkey}/Properties/{b}/CarouselImages/{propname}")
                        .PostAsync(img_6);
                    }
                    client.Dispose();
                    return true;
                }
                client.Dispose();
                return false;
            }
            catch
            {
                client.Dispose();
                return false;
            }

        }
Leave a Comment