Yasin Kızıltaş

Yasin Kızıltaş

  • NA
  • 57
  • 4.7k

How do I prevent data repetition in mvc?

Nov 26 2018 8:29 AM
Hello there. I am drawing data from the database according to a certain condition. however, the query repeats data in some cases and lists duplicate data. How do I prevent this?
 
TekrarAraV View;
  1. @model IEnumerable<cmsV0._1.Models.vw_get_callLog>    
  2. @{    
  3.     ViewBag.Title = "Tekrar Ara";    
  4.     string userRols = ViewBag.userRoler;    
  5.     int i = 1;    
  6.     
  7. }    
  8. <br />    
  9.     <form action="/Rapor/TekrarAraV" method="get">    
  10.         <input type="text" name="date" id="date" class="form-control" />    
  11.         <input type="submit" value="Getir" />    
  12.     </form>    
  13.     
  14.     
  15.     
  16. <div style="display:none;">@DateTime.UtcNow.AddHours(3).AddMinutes(5).ToString("dd/MM/yyy")</div>    
  17. <br /><br />    
  18. <table class="table">    
  19.     <thead>    
  20.         <tr>    
  21.                
  22.             <th></th>    
  23.             <td>    
  24.                 <b style="font-size:medium;padding-left:15px;">Ad</b>    
  25.             </td>    
  26.             <td>    
  27.                 <b style="font-size:medium;">Telefon</b>    
  28.             </td>    
  29.             <td>    
  30.                             <b>Mail</b>    
  31.             </td>    
  32.             <td>    
  33.                 <b style="font-size:medium;">Durum</b>    
  34.             </td>    
  35.             <td style="color:red;font-size:medium;width:20%;text-align:center;">    
  36.                 <b style="font-size:medium;">Aranacak Tarih</b>    
  37.             </td>    
  38.             <td>    
  39.                 <b style="font-size:medium;">Notu</b>    
  40.             </td>    
  41.             @if (userRols == "admin")    
  42.             {    
  43.                 <td>    
  44.                     <b style="font-size:medium;">Sorumlu TMK</b>    
  45.                 </td>    
  46.             }    
  47.         </tr>    
  48.         @foreach (var item in Model)    
  49.         {    
  50.             <tr>    
  51.                 <td>    
  52.                     @i    
  53.                 </td>    
  54.                 <td style="padding-left:20px;">    
  55.                     @item.flowName    
  56.                 </td>    
  57.                 <td>    
  58.                     @item.flowPhone    
  59.                 </td>    
  60.                 <td>    
  61.                     @item.flowEMail    
  62.                 </td>    
  63.                 <td>    
  64.                     @item.firstStatusText    
  65.                 </td>    
  66.                 <td style="text-align:center;">    
  67.                     @Convert.ToDateTime(item.callDate).ToString("dd/MM/yyy")    
  68.                     <span style="margin-left:10px;">@item.tekrarSaat</span>    
  69.                 </td>    
  70.                 <td>    
  71.                     @item.notes    
  72.                 </td>    
  73.     
  74.                 @if (userRols == "admin")    
  75.                 {    
  76.                     <td>    
  77.                         @item.tmkName    
  78.                     </td>    
  79.                 }    
  80.                 <td>    
  81.                     @Html.ActionLink("Çagri Aç""Edit""flows",new { id = item.flowId }, new { target = "_blank" })    
  82.                 </td>    
  83.     
  84.             </tr>    
  85.             i++;    
  86.         }    
  87.     </thead>    
  88. </table>    
  89. <script>    
  90.     function filterDate() {    
  91.         var input, filter, table, tr, td, i;    
  92.         input = document.getElementById("flowSearchN");    
  93.         filter = input.value.toUpperCase();    
  94.         table = document.getElementById("calendarM");    
  95.         tr = table.getElementsByTagName("tr");    
  96.         for (i = 0; i < tr.length; i++) {    
  97.             td = tr[i].getElementsByTagName("td")[3];    
  98.             if (td) {    
  99.                 if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {    
  100.                     tr[i].style.display = "";    
  101.                 } else {    
  102.                     tr[i].style.display = "none";    
  103.                 }    
  104.             }    
  105.         }    
  106.     }    
  107. </script>  
RaporController;
  1. public ActionResult TekrarAraV(DateTime? date)  
  2.        {  
  3.            userData = userControl(); ViewBag.uData = userData;  
  4.            string userName = userData.tmkName;  
  5.   
  6.            using (smartCMSEntities ft = new smartCMSEntities())  
  7.            {  
  8.                string userRol = userData.role;  
  9.                ViewBag.userRoler = userRol;  
  10.   
  11.   
  12.                if (date == null && userRol == "admin")  
  13.                {  
  14.                    return View(ft.vw_get_callLog.Where(x => x.firstStatusText == "Tekrar Ara" & x.callDate != null & x.callDate == DateTime.Today).ToList());  
  15.                }  
  16.   
  17.                else if (date == null)  
  18.                {  
  19.                    return View(ft.vw_get_callLog.Where(x => x.firstStatusText == "Tekrar Ara" & x.callDate != null & x.tmkName == userName & x.callDate == DateTime.Today).ToList());  
  20.                }  
  21.   
  22.                else if (userRol == "admin")  
  23.                {  
  24.                    return View(ft.vw_get_callLog.Where(x => x.firstStatusText == "Tekrar Ara" & x.callDate != null & x.callDate == date).ToList());  
  25.                }  
  26.                else  
  27.                {  
  28.                    return View(ft.vw_get_callLog.Where(x => x.firstStatusText == "Tekrar Ara" & x.callDate != null & x.tmkName == userName & x.callDate == date).ToList());  
  29.                }  
  30.   
  31.            }  
  32.        }  
 

Answers (2)