public bool followvendor(int user_id, int vendor_id) { List <Following_table> myRecord = context.Following_table.Where(s => s.User_id == user_id && s.Vendor_id == vendor_id).Select(s => s).ToList(); if (myRecord.Count() == 0) { Following_table model = new Following_table() { User_id = user_id, Vendor_id = vendor_id }; context.Following_table.Add(model); context.SaveChanges(); } return(true); }
public void RegisterFollowedVendor(string[] SelectedVendor, int id) { for (int i = 0; i < SelectedVendor.Length; i++) { string selected = SelectedVendor[i]; int vendorid = context.User_table.Where(x => x.User_Name.Equals(selected)).Select(x => x.User_Id).FirstOrDefault(); Vendors.Add(vendorid); } Following_table followVendor = new Following_table(); for (int i = 0; i < Vendors.Count(); i++) { followVendor.User_id = id; followVendor.Vendor_id = Vendors[i]; context.Following_table.Add(followVendor); context.SaveChanges(); } }