Esempio n. 1
0
        async Task <UnitDetailsModel> GetUnitFromDB(int?unitId, int?inventoryId, bool includeRCI = false)
        {
            var model = await
                            (from u in _context.Units
                            join c in _context.Translators on new { Reference = u.country, Type = "COUNTRY", Language = "EN" } equals new { c.Reference, c.Type, c.Language }
                            join s in _context.Translators on new { Reference = u.state, Type = "_S_" + u.country, Language = "EN" } equals new { s.Reference, s.Type, s.Language } into States
                            from St in States.DefaultIfEmpty()
                            join r in _context.Regions on u.regioncode equals r.regioncode into Regions
                            from Rg in Regions.DefaultIfEmpty()
                            join i in _context.Inventories on u.keyid equals i.unitkeyid into Inventories
                            from Ig in Inventories.DefaultIfEmpty()
                            where u.keyid == (unitId ?? u.keyid) &&
                            Ig.keyid == (inventoryId ?? Ig.keyid)
                            select new UnitDetailsModel()
            {
                Description    = u.info,
                ImageURL       = $"http://accessrsi.com/dannoJR/ProductImageHandler.ashx?imageid={u.thumbID}",
                OwnerId        = u.ownerid,
                OriginalUnitId = u.origionalid,
                UnitId         = u.keyid,
                UnitName       = u.name,
                Address        = new AddressViewModel()
                {
                    City            = u.city,
                    CountryCode     = u.country,
                    CountryFullName = c.Value,
                    PostalCode      = u.zip,
                    RegionCode      = u.regioncode,
                    RegionFullName  = Rg.regiondescription,
                    StateCode       = u.state,
                    StateFullName   = St.Value,
                    StreetAddress   = u.address.Trim()
                }
            }).FirstOrDefaultAsync <UnitDetailsModel>();

            if (model != null)
            {
                model.Amenities = await
                                      (from a in _context.Amenities
                                      where a.unitkeyid == unitId
                                      orderby a.sorder
                                      select new Amenity()
                {
                    Location = a.location,
                    Name     = a.ref1,
                    Distance = a.distance,
                    MK       = a.mk
                }).ToListAsync();

                var urgentInfo = await _context.LoadStoredProc("dbo.vipUrgentInfo")
                                 .WithSqlParam("resortID", unitId)
                                 .ExecuteStoredProcAsync <vipUrgentInfoResult>();

                model.UrgentInfo = urgentInfo.Select(u => u.urgentInfo).ToList();

                if (model.OwnerId == 100)
                {
                    model.AdditionalImageURLs = new List <string>()
                    {
                        $"http://rci.accessrsi.com/api/rci/getImage?resortId={model.OriginalUnitId}"
                    };
                }
                else
                {
                    model.AdditionalImageURLs = await
                                                    (from p in _context.Pics
                                                    where p.ptype == "U_PIC" && p.ref1 == model.UnitId.ToString()
                                                    select $"http://accessrsi.com/dannoJR/ProductImageHandler.ashx?imageid={p.keyid}").ToListAsync();
                }
            }

            if (model != null)
            {
                model.Message = "Success";
            }
            return(model ?? new UnitDetailsModel()
            {
                Message = "Error: Unit Not Found"
            });
        }