/// <summary> /// الحصول على جميع معلومات اعلان معين بالاضافة الى آخر 10 تعليقات /// </summary> /// <param name="adId"></param> /// <returns></returns> public object GetAdDetailsById(int adId) { var Ad = db.Ads.Find(adId); int UserId = AccessToken.GetUserId(); if (Ad == null) { return(new ResponseVM(RequestTypeEnumVM.Error, Token.AdNotFound)); } return(new ResponseVM(RequestTypeEnumVM.Success, Token.Success, new AdDetailsVM { Id = Ad.Id, Title = Ad.Title, Description = Ad.Description, Price = Ad.Price.ToString(), UserName = Ad.User.UserName, Province = Ad._Province, SinceDateTime = Ad._Time, Images = Ad.Album.AlbumFiles.Select(v => v.File.FullFileUrl), AdPath = Ad._AdPath, PhoneNumbre = Ad.User.UserInformation.PhoneNumber, FooterValues = GetBottomBar(Ad), AdComments = Ad.AdComments.OrderByDescending(c => c.Id).Skip(0).Take(10).Select(c => CommData.GetCommentInfrmation(c)), CategoryName = Ad.Category.CategoryName, SubCategoryName = Ad.SubCategory.SubCategoryName, RentalTimeTypeName = Ad.RentalTimesType.RentalTimeTypeName, AdIndividualFieldsDetails = Ad.AdIndividualFieldsDetails.Select(c => new AdIndividualFieldsDetailsVM { IndividualFieldId = c.FkIndividualField_Id, Value = c.Value, IndividualFieldName = c.IndividualField.IndividualFieldName }).ToList(), //Direct Fields AdDirectFieldDetails = new AdDirectFieldDetailsVM { Area = AdService.GetAdValue("Area", Ad.AdDirectFieldDetail.Area), Location = AdService.GetAdValue("Location", Ad.AdDirectFieldDetail.Location), Country = AdService.GetAdValue("Country", Ad.AdDirectFieldDetail.Country), Province = AdService.GetAdValue("Province", Ad.AdDirectFieldDetail.Province), Mark = AdService.GetAdValue("Mark", Ad.AdDirectFieldDetail.Mark), Material = AdService.GetAdValue("Material", Ad.AdDirectFieldDetail.Material), Nationality = AdService.GetAdValue("Nationality", Ad.AdDirectFieldDetail.Nationality), Size = AdService.GetAdValue("Size", Ad.AdDirectFieldDetail.Size), }, AdGroupsDetails = Ad.AdGroupsDetails.Select(c => new { GroupId = c.FKGroup_Id, GroupName = c.Group.GroupName, Value = c.Value }).GroupBy(v => new { v.GroupName, v.GroupId }, (group, values) => new AdGroupsDetailsVM { GroupId = group.GroupId, GroupName = group.GroupName, Values = values.Select(c => c.Value) } ).ToList() })); }