public ActionResult <CompareListResponseModel> ViewCompare([FromBody] CompareListInputModel data) { CompareListResponseModel res = new CompareListResponseModel(); try { CompareBL bl = new CompareBL(DbContext); var temp = bl.GetCompareList(data); res.data = temp; res.Message = "Success"; res.Response = true; return(res); } catch (Exception ex) { res.Message = ex.Message; res.Response = false; return(res); } }
public List <CompareListResultModel> GetCompareList(CompareListInputModel data) { var temp = db.Compare.Where(x => x.UserID == data.UserID && x.DeletedDate == null).ToList(); List <CompareListResultModel> listCompare = new List <CompareListResultModel>(); if (temp != null && temp.Count > 0) { foreach (var select in temp) { var headQuery = (from head in db.TitikLokasi where head.ID == @select.SiteID select new CompareListDetailModel() { SiteID = head.ID, CompareID = @select.ID, Cabang = head.Cabang, HorV = head.HorV, Kota = head.Kota, Pulau = head.Pulau, Latitude = head.Latitude, Longitude = head.Longitude, NoBillboard = head.NoBillboard, Tipe = head.Type, Provinsi = head.Provinsi, RateScoreAverage = head.RateScoreAverage, }).FirstOrDefault(); var ItemQuery = (from item in db.TitikLokasiDetail where item.TitikLokasiID == @select.SiteID select new CompareListSiteItemModel() { ArahLokasi = item.ArahLokasi, SiteID = item.TitikLokasiID, KodeLokasi = item.KodeArahLokasi, SiteItemID = item.ID, Panjang = item.Panjang, Lebar = item.Lebar, Price = db.TitikLokasiPrice.Where(x => x.TitikLokasiDetailID == item.ID).Select(x => new CompareListPriceModel { SitePriceID = x.ID, SiteItemID = x.TitikLokasiDetailID, Dasar = x.Dasar, HargaAkhir = x.HargaAkhir, HargaAwal = x.HargaAwal, Kelipatan = x.Kelipatan }).ToList(), Image = db.TitikLokasiImage.Where(x => x.TitikLokasiDetailID == item.ID).Select(x => new CompareListImageModel { SiteImageID = x.ID, SiteItemID = x.TitikLokasiDetailID, Image = x.PathImage }).ToList() }).ToList(); CompareListResultModel resData = new CompareListResultModel(); resData.Detail = headQuery; resData.Item = ItemQuery; listCompare.Add(resData); } } return(listCompare); }
public IActionResult ViewCompare() { List <CompareListResultModel> OutPutData = new List <CompareListResultModel>(); StringBuilder sb = new StringBuilder(); CompareListInputModel filter = new CompareListInputModel(); filter.UserID = Guid.Parse(HttpContext.Session.GetString(SessionKeyID)); using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseAPI + "Site/"); var responseTask = client.PostAsJsonAsync <CompareListInputModel>("ViewCompare", filter); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var content = result.Content.ReadAsStringAsync(); CompareListResponseModel resutl = Newtonsoft.Json.JsonConvert.DeserializeObject <CompareListResponseModel>(content.Result); OutPutData = resutl.data; if (OutPutData.Count > 3) { for (int j = 0; j < 3; j++) { var quote = "'"; sb.Append("<div class='column'>"); BillboardDetail dataBillboard = new BillboardDetail(); if (OutPutData[j].Item != null && OutPutData[j].Item.Count > 0) { var item = OutPutData[j].Item; foreach (CompareListSiteItemModel data in item) { dataBillboard.Pjg = data.Panjang; dataBillboard.Lbr = data.Lebar; if (data.Price != null) { dataBillboard.Hawl = data.Price[0].HargaAwal; dataBillboard.Hahr = data.Price[0].HargaAkhir; } else { dataBillboard.Hawl = 0; dataBillboard.Hahr = 0; } if (data.Image != null && data.Image.Count > 0) { dataBillboard.Img = data.Image[0].Image; } else { dataBillboard.Img = "-"; } } } if (OutPutData[j].Detail != null) { if (dataBillboard.Img == "-") { sb.Append("<div class='viewprod'>Photo not available</div>"); } else { sb.Append("<img src='" + dataBillboard.Img + "' class='listimage'/>"); } sb.Append("<div class='detailprod'>"); sb.Append("<p class='pheader'>" + OutPutData[j].Detail.NoBillboard + "</p>"); sb.Append("<p class='pdetail'>Alamat Lokasi Billboard</p>"); sb.Append("<p class='pdetail'>Tipe : " + OutPutData[j].Detail.Tipe + "</p>"); sb.Append("<p class='pdetail'>Ukuran : " + dataBillboard.Pjg + " X " + dataBillboard.Lbr + "</p>"); sb.Append("<p class='pdetail'>H/V : " + OutPutData[j].Detail.HorV + "</p>"); sb.Append("</div>"); sb.Append("<div class='detailprice'>"); sb.Append("<p>Rp. <span class='price'>" + Convert.ToDecimal(dataBillboard.Hawl).ToString("#,##0") + "</span>,-</p>"); sb.Append("</div>"); sb.Append("<div class='detailbtn'>"); if (Domain != "") { sb.Append("<input type=\"button\" value=\"Delete\" style=\"padding: 5px 10px; font - size: 15px; margin: 5px 5px;\" onclick=\"deleteCompare('/" + Domain + "/Rest/DeleteFromCompare','" + OutPutData[j].Detail.CompareID + "')\" />"); } else { sb.Append("<input type=\"button\" value=\"Delete\" style=\"padding: 5px 10px; font - size: 15px; margin: 5px 5px;\" onclick=\"deleteCompare('/Rest/DeleteFromCompare','" + OutPutData[j].Detail.CompareID + "')\" />"); } sb.Append("</div>"); } sb.Append("</div>"); } } else { for (int j = 0; j < OutPutData.Count; j++) { var quote = "'"; sb.Append("<div class='column'>"); BillboardDetail dataBillboard = new BillboardDetail(); if (OutPutData[j].Item != null && OutPutData[j].Item.Count > 0) { var item = OutPutData[j].Item; foreach (CompareListSiteItemModel data in item) { dataBillboard.Pjg = data.Panjang; dataBillboard.Lbr = data.Lebar; if (data.Price != null) { dataBillboard.Hawl = data.Price[0].HargaAwal; dataBillboard.Hahr = data.Price[0].HargaAkhir; } else { dataBillboard.Hawl = 0; dataBillboard.Hahr = 0; } if (data.Image != null && data.Image.Count > 0) { dataBillboard.Img = data.Image[0].Image; } else { dataBillboard.Img = "-"; } } } if (OutPutData[j].Detail != null) { if (dataBillboard.Img == "-") { sb.Append("<div class='viewprod'>Photo not available</div>"); } else { sb.Append("<img src='" + dataBillboard.Img + "' class='listimage'/>"); } sb.Append("<div class='detailprod'>"); sb.Append("<p class='pheader'>" + OutPutData[j].Detail.NoBillboard + "</p>"); sb.Append("<p class='pdetail'>Alamat Lokasi Billboard</p>"); sb.Append("<p class='pdetail'>Tipe : " + OutPutData[j].Detail.Tipe + "</p>"); sb.Append("<p class='pdetail'>Ukuran : " + dataBillboard.Pjg + " X " + dataBillboard.Lbr + "</p>"); sb.Append("<p class='pdetail'>H/V : " + OutPutData[j].Detail.HorV + "</p>"); sb.Append("</div>"); sb.Append("<div class='detailprice'>"); sb.Append("<p>Rp. <span class='price'>" + Convert.ToDecimal(dataBillboard.Hawl).ToString("#,##0") + "</span>,-</p>"); sb.Append("</div>"); sb.Append("<div class='detailbtn'>"); if (Domain != "") { sb.Append("<input type=\"button\" value=\"Delete\" style=\"padding: 5px 10px; font - size: 15px; margin: 5px 5px;\" onclick=\"deleteCompare('/" + Domain + "/Rest/DeleteFromCompare','" + OutPutData[j].Detail.CompareID + "')\" />"); } else { sb.Append("<input type=\"button\" value=\"Delete\" style=\"padding: 5px 10px; font - size: 15px; margin: 5px 5px;\" onclick=\"deleteCompare('/Rest/DeleteFromCompare','" + OutPutData[j].Detail.CompareID + "')\" />"); } sb.Append("</div>"); } sb.Append("</div>"); } } return(this.Content(sb.ToString())); } else //web api sent error response { //log response status here.. //OutPutData = Enumerable.Empty<CompareListResultModel>(); ModelState.AddModelError(string.Empty, "Terjadi kesalahan. Mohon hubungi admin."); } } return(Json(OutPutData)); }