public int UpdateEvent(EventModel obj) { int result = 0; CheckForLocation_Event(ref obj, obj); using (RSEntities objEnt = new RSEntities()) { var oData = objEnt.RS_Event.Where(i => i.EventId == obj.EventId).First(); oData.EventType = obj.EventType; oData.Subject = obj.Subject; oData.Body = obj.Body; oData.EventDateFrom = obj.EventDateFrom; oData.EventTimeFrom = obj.EventTimeFrom; oData.EventDateTo = obj.EventDateTo; oData.EventTimeTo = obj.EventTimeTo; oData.Location = obj.LocationName; oData.District = obj.DistrictName; oData.ModifiedBy = obj.ModifiedBy; oData.ModifiedOn = DateTime.Now; oData.IsActive = true; result = objEnt.SaveChanges(); } return(result); }
public int InsertEvent(EventModel obj) { int result = 0; CheckForLocation_Event(ref obj, obj); using (RSEntities objEnt = new RSEntities()) { RS_Event oData = new RS_Event(); oData.EventType = obj.EventType; oData.Subject = obj.Subject; oData.Body = obj.Body; oData.EventDateFrom = obj.EventDateFrom; oData.EventTimeFrom = obj.EventTimeFrom; oData.EventDateTo = obj.EventDateTo; oData.EventTimeTo = obj.EventTimeTo; oData.Location = obj.LocationName; oData.District = obj.DistrictName; oData.CreatedBy = obj.CreatedBy; oData.CreatedOn = DateTime.Now; oData.IsActive = true; //oData.CreatedOn = ; //oData.Location = obj.Location; //oData.IpAddress = obj.IpAddress; objEnt.RS_Event.Add(oData); result = objEnt.SaveChanges(); } return(result); }
private EventModel CheckForLocation_Event(ref EventModel result, EventModel obj) { RS_EventType EventTypeResult = new RS_EventType(); using (RSEntities objEnt = new RSEntities()) { if (obj.EventTypeName.Trim() != string.Empty) { /// Checking for current location present or not var EventType = objEnt.RS_EventType.Where(o => o.EventType.Trim().ToUpper() == obj.EventTypeName.Trim().ToUpper()); if (EventType.Count() > 0) { EventTypeResult = EventType.FirstOrDefault(); } else { RS_EventType oData = new RS_EventType(); oData.EventType = obj.EventTypeName; oData.CreatedOn = DateTime.Now; oData.CreatedBy = obj.CreatedBy; objEnt.RS_EventType.Add(oData); objEnt.SaveChanges(); EventTypeResult = oData; } } result.EventType = EventTypeResult != null && EventTypeResult.EventTypeId != 0 ? EventTypeResult.EventTypeId : (int?)null; } return(result); }
public EventModel GetEventId(int Id) { EventModel result = new EventModel(); using (RSEntities ent = new RSEntities()) { result = (from obj in ent.RS_Event from ET in ent.RS_EventType.Where(ET => ET.EventTypeId == obj.EventType).DefaultIfEmpty() // <== makes join left join // from CDs in ent.RS_District.Where(CD => CD.DistrictId == obj.District).DefaultIfEmpty() // <== makes join left join // from CLs in ent.RS_Location.Where(CL => CL.LocationId == obj.Location).DefaultIfEmpty() // <== makes join left join from RD in ent.RS_RathoreDetails.Where(RDs => RDs.RathoreDetailId == obj.CreatedBy).DefaultIfEmpty() // <== makes join left join where obj.EventId == Id select new EventModel { EventId = obj.EventId, Subject = obj.Subject, Body = obj.Body, EventDateFrom = obj.EventDateFrom, EventTimeFrom = obj.EventTimeFrom, EventDateTo = obj.EventDateTo, EventTimeTo = obj.EventTimeTo, LocationName = obj.Location, DistrictName = obj.District, CreatedOn = obj.CreatedOn, CreatedBy = obj.CreatedBy, CreatedByName = RD.Name, EventTypeName = ET.EventType, ModifiedBy = obj.ModifiedBy, }).ToList().FirstOrDefault(); } return(result); }
public RathoreDetailDisplayModel GetDetailsToDisplay() { RathoreDetailDisplayModel objRathoreDetails = new RathoreDetailDisplayModel(); using (RSEntities ent = new RSEntities()) { var rathoreDetails = from obj in ent.RS_RathoreDetails from CSs in ent.RS_State.Where(CS => CS.StateId == obj.CurrentState).DefaultIfEmpty() from CDs in ent.RS_District.Where(CD => CD.DistrictId == obj.CurrentDistrict).DefaultIfEmpty() select new RathoreDetailModel { RathoreDetailId = obj.RathoreDetailId, CurrentState = obj.CurrentState, CurrentStateName = CSs.StateName, CurrentDistrict = obj.CurrentDistrict, CurrentDistrictName = CDs.DistrictName, }; var results = rathoreDetails.GroupBy(p => new { p.CurrentState, p.CurrentStateName }, p => p, (key, g) => new { CurrentState = key.CurrentState, CurrentStateName = key.CurrentStateName, Count = g.Count() }); var resultsDist = rathoreDetails.GroupBy(p => new { p.CurrentState, p.CurrentDistrictName }, p => p, (key, g) => new { CurrentState = key.CurrentState, CurrentDistrictName = key.CurrentDistrictName, Count = g.Count() }); List <TreeResultbase> stateBasedDetail = new List <TreeResultbase>(); objRathoreDetails.StateBasedDetails = new List <TreeResultbase>(); foreach (var val in results) { TreeResultbase oValue = new TreeResultbase(); oValue.Id = val.CurrentState; oValue.Name = val.CurrentStateName; oValue.Value = val.Count; stateBasedDetail.Add(oValue); } // foreach(var o in ) objRathoreDetails.StateBasedDetails = stateBasedDetail.OrderByDescending(o => o.Value).ToList(); objRathoreDetails.DistrictBasedDetails = new List <TreeResultbase>(); foreach (var val in resultsDist) { TreeResultbase oValue = new TreeResultbase(); oValue.Id = val.CurrentState; oValue.Name = val.CurrentDistrictName; oValue.Value = val.Count; objRathoreDetails.DistrictBasedDetails.Add(oValue); } //objRathoreDetails.DistrictBasedDetails = from obj in objEnt.RS_RathoreDetails // group } return(objRathoreDetails); }
public Dictionary <int, string> GetEventType() { Dictionary <int, string> result = new Dictionary <int, string>(); using (RSEntities ent = new RSEntities()) { result = ent.RS_EventType.Select(t => new { t.EventTypeId, t.EventType }).ToDictionary(t => t.EventTypeId, t => t.EventType); } return(result); }
public Dictionary <int, string> GetAllLocation() { Dictionary <int, string> result = new Dictionary <int, string>(); using (RSEntities ent = new RSEntities()) { result = ent.RS_Location.Select(t => new { t.LocationId, t.LocationName }).ToDictionary(t => t.LocationId, t => t.LocationName); } return(result); }
public Dictionary <int, string> GetAllDistrict() { Dictionary <int, string> result = new Dictionary <int, string>(); using (RSEntities ent = new RSEntities()) { result = ent.RS_District.Select(t => new { t.DistrictId, t.DistrictName }).ToDictionary(t => t.DistrictId, t => t.DistrictName); } return(result); }
public Dictionary <int, string> GetAllCountry() { Dictionary <int, string> result = new Dictionary <int, string>(); using (RSEntities ent = new RSEntities()) { result = ent.RS_Country.Select(t => new { t.CountryId, t.CountryName }).ToDictionary(t => t.CountryId, t => t.CountryName); } return(result); }
public int UpdateRathoreDetail(RathoreDetailModel obj) { int result = 0; using (RSEntities objEnt = new RSEntities()) { CheckForCurrentLocationDetail(ref obj, obj); CheckForNativeLocationDetail(ref obj, obj); var oData = objEnt.RS_RathoreDetails.Where(i => i.RathoreDetailId == obj.RathoreDetailId).First(); oData.Name = obj.Name; oData.FatherName = obj.FatherName; oData.MotherName = obj.MotherName; oData.DateOfBirth = obj.DateOfBirth; oData.PhoneNumber = obj.PhoneNumber; oData.Occupation = obj.Occupation; oData.gender = obj.Gender; oData.IsMarried = obj.IsMarried; oData.SpouseName = obj.SpouseName; oData.CurrentCountry = obj.CurrentCountry; oData.CurrentState = obj.CurrentState; oData.CurrentDistrict = obj.CurrentDistrict; oData.CurrentLocation = obj.CurrentLocation; oData.CurrentAddress = obj.CurrentAddress; oData.NativeCountry = obj.NativeCountry; oData.NativeState = obj.NativeState; oData.NativeDistrict = obj.NativeDistrict; oData.NativeLocation = obj.NativeLocation; oData.NativeAddress = obj.NativeAddress; oData.EmailId = obj.EmailId; oData.FinalEducation = obj.FinalEducation; oData.NoOfChildern = obj.NoOfChildern; oData.ModifiedBy = obj.ModifiedBy; oData.ModifiedOn = DateTime.Now; oData.IsActive = true; oData.UserName = obj.UserName; oData.Password = obj.Password; oData.Role = obj.Role; //oData.CreatedOn = ; //oData.Location = obj.Location; //oData.IpAddress = obj.IpAddress; //objEnt.RS_RathoreDetails.Add(oData); result = objEnt.SaveChanges(); } return(result); }
public int DeleteRathoreDetail(int rathoreDetailId) { int result = 0; using (RSEntities obj = new RSEntities()) { var oSelect = obj.RS_RathoreDetails.First(i => i.RathoreDetailId == rathoreDetailId); obj.RS_RathoreDetails.Remove(oSelect); result = obj.SaveChanges(); } return(result); }
public int DeleteContact(int Id) { int result = 0; using (RSEntities obj = new RSEntities()) { var oSelect = obj.RS_ContactUs.First(i => i.ContactusId == Id); obj.RS_ContactUs.Remove(oSelect); result = obj.SaveChanges(); } return(result); }
public int DeleteEvent(int Id) { int result = 0; using (RSEntities obj = new RSEntities()) { var oSelect = obj.RS_Event.First(i => i.EventId == Id); obj.RS_Event.Remove(oSelect); result = obj.SaveChanges(); } return(result); }
public bool CheckRathoreDetailExist(string fullName, DateTime?BirthDate) { bool isExist = false; using (RSEntities ent = new RSEntities()) { var result = ent.RS_RathoreDetails.Where(obj => obj.Name == fullName && obj.DateOfBirth == BirthDate).Count(); if (result > 0) { isExist = true; } } return(isExist); }
/// <summary> /// Update the login detail information /// </summary> /// <param name="lm"></param> /// <returns></returns> public int UpdateLoginInfoDetail(LoginModel lm) { int result = 0; using (RSEntities obj = new RSEntities()) { var oData = obj.RS_RathoreDetails.First(i => i.RathoreDetailId == lm.RathoreDetailId); oData.LastLogin = DateTime.Now; oData.LoginCount = oData.LoginCount == null ? 1 : oData.LoginCount + 1; oData.ModifiedOn = DateTime.Now; oData.ModifiedBy = lm.RathoreDetailId; result = obj.SaveChanges(); } return(result); }
/// <summary> /// Checking the login details /// </summary> /// <param name="lm"></param> /// <returns></returns> public LoginModel CheckLoginDetail(LoginModel lm) { LoginModel result = new LoginModel(); using (RSEntities obj = new RSEntities()) { result = (from odata in obj.RS_RathoreDetails where odata.UserName == lm.UserName && odata.Password == lm.Password select new LoginModel { RathoreDetailId = odata.RathoreDetailId, Name = odata.Name, UserName = odata.UserName, LastLogin = odata.LastLogin, LoginCount = odata.LoginCount, Role = odata.Role }).FirstOrDefault(); } return(result); }
public ContactModel GetContactId(int id) { ContactModel result = new ContactModel(); using (RSEntities obj = new RSEntities()) { result = (from odata in obj.RS_ContactUs where odata.ContactusId == id select new ContactModel { Name = odata.Name, PhoneNumber = odata.PhoneNumber, EmailId = odata.EmailId, Subject = odata.Subject, Body = odata.Body, Location = odata.Location, IpAddress = odata.IpAddress }).First(); } return(result); }
public List <ContactModel> GetAllContactDetail() { List <ContactModel> result = new List <ContactModel>(); using (RSEntities obj = new RSEntities()) { result = (from odata in obj.RS_ContactUs select new ContactModel { ContactusId = odata.ContactusId, Name = odata.Name, PhoneNumber = odata.PhoneNumber, EmailId = odata.EmailId, Subject = odata.Subject, CreatedOn = odata.CreatedOn, Body = odata.Body, Location = odata.Location, IpAddress = odata.IpAddress }).ToList(); } return(result); }
public int InsertContact(ContactModel obj) { int result = 0; using (RSEntities objEnt = new RSEntities()) { RS_ContactUs oData = new RS_ContactUs(); oData.Name = obj.Name; oData.PhoneNumber = obj.PhoneNumber; oData.EmailId = obj.EmailId; oData.Body = obj.Body; oData.Subject = obj.Subject; oData.CreatedOn = DateTime.Now; oData.Location = obj.Location; oData.IpAddress = obj.IpAddress; objEnt.RS_ContactUs.Add(oData); result = objEnt.SaveChanges(); } return(result); }
public RathoreDetailModel GetRathoreDetailId(int rathoreDetailId) { RathoreDetailModel result = new RathoreDetailModel(); using (RSEntities ent = new RSEntities()) { result = (from obj in ent.RS_RathoreDetails from CCs in ent.RS_Country.Where(CC => CC.CountryId == obj.CurrentCountry).DefaultIfEmpty() // <== makes join left join from CSs in ent.RS_State.Where(CS => CS.StateId == obj.CurrentState).DefaultIfEmpty() // <== makes join left join from CDs in ent.RS_District.Where(CD => CD.DistrictId == obj.CurrentDistrict).DefaultIfEmpty() // <== makes join left join from CLs in ent.RS_Location.Where(CL => CL.LocationId == obj.CurrentLocation).DefaultIfEmpty() // <== makes join left join from NCs in ent.RS_Country.Where(CC => CC.CountryId == obj.NativeCountry).DefaultIfEmpty() // <== makes join left join from NSs in ent.RS_State.Where(CS => CS.StateId == obj.NativeState).DefaultIfEmpty() // <== makes join left join from NDs in ent.RS_District.Where(CD => CD.DistrictId == obj.NativeDistrict).DefaultIfEmpty() // <== makes join left join from NLs in ent.RS_Location.Where(CL => CL.LocationId == obj.NativeLocation).DefaultIfEmpty() // <== makes join left join where obj.RathoreDetailId == rathoreDetailId select new RathoreDetailModel { RathoreDetailId = obj.RathoreDetailId, Name = obj.Name, FatherName = obj.FatherName, MotherName = obj.MotherName, DateOfBirth = obj.DateOfBirth, PhoneNumber = obj.PhoneNumber, Occupation = obj.Occupation, IsMarried = obj.IsMarried, SpouseName = obj.SpouseName, Gender = obj.gender, CurrentCountry = obj.CurrentCountry, CurrentCountryName = CCs.CountryName, CurrentState = obj.CurrentState, CurrentStateName = CSs.StateName, CurrentDistrict = obj.CurrentDistrict, CurrentDistrictName = CDs.DistrictName, CurrentLocation = obj.CurrentLocation, CurrentLocationName = CLs.LocationName, NativeCountry = obj.NativeCountry, NativeState = obj.NativeState, NativeDistrict = obj.NativeDistrict, NativeLocation = obj.NativeLocation, NativeCountryName = NCs.CountryName, NativeStateName = NSs.StateName, NativeDistrictName = NDs.DistrictName, NativeLocationName = NLs.LocationName, UserName = obj.UserName, Password = obj.Password, Role = obj.Role, CurrentAddress = obj.CurrentAddress, NativeAddress = obj.NativeAddress, EmailId = obj.EmailId, FinalEducation = obj.FinalEducation, NoOfChildern = obj.NoOfChildern, ModifiedBy = obj.ModifiedBy, }).First(); } return(result); }
public ActionResult com_login() { RSEntities db = new RSEntities(); string status = ""; Commander Comer = new Commander(); #region مقدارهای اولیه int User_id; string IP = System.Web.HttpContext.Current.Request.UserHostAddress; string direct_url = ""; try { direct_url = Request.UrlReferrer.Host; } catch (Exception) { } string password = Request.Form["val44"]; string username = Request.Form["val67"]; string language = Request.Form["val89"]; bool Check_Has_User = Comer.Has_Username_Login(username, password, out User_id); #endregion try { if (Check_Has_User) { RS_Account UserInfo = db.RS_Account.Single(u => u.Account_Id == User_id); ///============ دستور بهینه شده اطلاعات ورود =============/// ///==============================================================/// account_manage user_mgr = new account_manage(); Response.Cookies.Add(user_mgr.Login_HttpCookie(IP, UserInfo.RS_AccountInfo.AccountInfo_FirstName, UserInfo.RS_AccountInfo.AccountInfo_LastName, UserInfo.Account_Username, User_id, 72, UserInfo.RS_Language.Language_Iso)); FormsAuthentication.Initialize(); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddMonths(1), true, UserInfo.Account_RoleId.ToString(), FormsAuthentication.FormsCookiePath); string hash = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); if (ticket.IsPersistent) { cookie.Expires = ticket.Expiration; } //Navid : 2018-06-11 : Cooki Language : Response.Cookies["langName"].Value = language; Response.Cookies.Add(cookie); string returnUrl = Request.QueryString["ReturnUrl"]; if (returnUrl == null) { returnUrl = "/"; } //Response.Redirect("/j-admin"); status = "welcome"; } else { status = "noUser"; } } catch (Exception ex) { status = ex.Message; } ContentResult ctr_result = new ContentResult(); bool Bl = User.Identity.IsAuthenticated; string str = User.Identity.Name; ctr_result.Content = status; return(ctr_result); }
public List <RathoreDetailModel> GetAllRathoreDetail() { List <RathoreDetailModel> result = new List <RathoreDetailModel>(); using (RSEntities ent = new RSEntities()) { ////result = (from obj in ent.RS_RathoreDetails //// from CCs in ent.RS_Country.Where(CC => CC.CountryId == obj.CurrentCountry).DefaultIfEmpty() // <== makes join left join //// join CC in ent.RS_Country on obj.CurrentCountry equals CC.CountryId into ps //// from CC in ps.DefaultIfEmpty() //// join CS in ent.RS_State on obj.CurrentState equals CS.StateId //// join CD in ent.RS_District on obj.CurrentDistrict equals CD.DistrictId //// join CL in ent.RS_Location on obj.CurrentLocation equals CL.LocationId //// //join NC in ent.RS_Country on obj.CurrentCountry equals CC.CountryId //// //join CS in ent.RS_State on obj.CurrentState equals CS.StateId //// //join CD in ent.RS_District on obj.CurrentDistrict equals CD.DistrictId //// //join CL in ent.RS_Location on obj.CurrentLocation equals CL.LocationId result = (from obj in ent.RS_RathoreDetails from CCs in ent.RS_Country.Where(CC => CC.CountryId == obj.CurrentCountry).DefaultIfEmpty() // <== makes join left join from CSs in ent.RS_State.Where(CS => CS.StateId == obj.CurrentState).DefaultIfEmpty() // <== makes join left join from CDs in ent.RS_District.Where(CD => CD.DistrictId == obj.CurrentDistrict).DefaultIfEmpty() // <== makes join left join from CLs in ent.RS_Location.Where(CL => CL.LocationId == obj.CurrentLocation).DefaultIfEmpty() // <== makes join left join from NCs in ent.RS_Country.Where(CC => CC.CountryId == obj.NativeCountry).DefaultIfEmpty() // <== makes join left join from NSs in ent.RS_State.Where(CS => CS.StateId == obj.NativeState).DefaultIfEmpty() // <== makes join left join from NDs in ent.RS_District.Where(CD => CD.DistrictId == obj.NativeDistrict).DefaultIfEmpty() // <== makes join left join from NLs in ent.RS_Location.Where(CL => CL.LocationId == obj.NativeLocation).DefaultIfEmpty() // <== makes join left join select new RathoreDetailModel { RathoreDetailId = obj.RathoreDetailId, Name = obj.Name, FatherName = obj.FatherName, MotherName = obj.MotherName, DateOfBirth = obj.DateOfBirth, PhoneNumber = obj.PhoneNumber, Occupation = obj.Occupation, IsMarried = obj.IsMarried, SpouseName = obj.SpouseName, Gender = obj.gender, CurrentCountry = obj.CurrentCountry, CurrentCountryName = CCs.CountryName, CurrentState = obj.CurrentState, CurrentStateName = CSs.StateName, CurrentDistrict = obj.CurrentDistrict, CurrentDistrictName = CDs.DistrictName, CurrentLocation = obj.CurrentLocation, CurrentLocationName = CLs.LocationName, NativeCountry = obj.NativeCountry, NativeState = obj.NativeState, NativeDistrict = obj.NativeDistrict, NativeLocation = obj.NativeLocation, NativeCountryName = NCs.CountryName, NativeStateName = NSs.StateName, NativeDistrictName = NDs.DistrictName, NativeLocationName = NLs.LocationName, CurrentAddress = obj.CurrentAddress, NativeAddress = obj.NativeAddress, EmailId = obj.EmailId, FinalEducation = obj.FinalEducation, NoOfChildern = obj.NoOfChildern, ModifiedBy = obj.ModifiedBy, }).ToList(); } return(result); }
private RathoreDetailModel CheckForNativeLocationDetail(ref RathoreDetailModel result, RathoreDetailModel obj) { RS_Country NativeCountryResult = new RS_Country(); RS_State NativeStateResult = new RS_State(); RS_District NativeDistrictResult = new RS_District(); RS_Location NativeLocationResult = new RS_Location(); using (RSEntities objEnt = new RSEntities()) { if (obj.NativeCountryName.Trim() != string.Empty) { //// Checking that current inserted country is present or not var CurrentCountry = objEnt.RS_Country.Where(o => o.CountryName.Trim().ToUpper() == obj.NativeCountryName.Trim().ToUpper()); if (CurrentCountry.Count() > 0) { NativeCountryResult = CurrentCountry.FirstOrDefault(); } else { RS_Country oData = new RS_Country(); oData.CountryName = obj.NativeCountryName; oData.CreatedOn = DateTime.Now; oData.CreatedBy = obj.CreatedBy; objEnt.RS_Country.Add(oData); objEnt.SaveChanges(); NativeCountryResult = oData; result.CurrentCountry = NativeCountryResult.CountryId; } } result.NativeCountry = NativeCountryResult != null && NativeCountryResult.CountryId != 0 ? NativeCountryResult.CountryId : (int?)null; } using (RSEntities objEnt = new RSEntities()) { if (obj.NativeStateName.Trim() != string.Empty) { /// Checking for current state is present or nor var CurrentState = objEnt.RS_State.Where(o => o.StateName.Trim().ToUpper() == obj.NativeStateName.Trim().ToUpper()); if (CurrentState.Count() > 0) { NativeStateResult = CurrentState.FirstOrDefault(); } else { RS_State oData = new RS_State(); oData.CountryId = NativeCountryResult.CountryId; oData.StateName = obj.NativeStateName; oData.CreatedOn = DateTime.Now; oData.CreatedBy = obj.CreatedBy; objEnt.RS_State.Add(oData); objEnt.SaveChanges(); NativeStateResult = oData; } } result.NativeState = NativeStateResult != null && NativeStateResult.StateId != 0 ? NativeStateResult.StateId : (int?)null; } using (RSEntities objEnt = new RSEntities()) { if (obj.NativeDistrictName.Trim() != string.Empty) { /// Checking for current district present or not var CurrentDistrict = objEnt.RS_District.Where(o => o.DistrictName.Trim().ToUpper() == obj.NativeDistrictName.Trim().ToUpper()); if (CurrentDistrict.Count() > 0) { NativeDistrictResult = CurrentDistrict.FirstOrDefault(); } else { RS_District oData = new RS_District(); oData.DistrictName = obj.NativeDistrictName; oData.StateId = NativeStateResult.StateId; oData.CreatedOn = DateTime.Now; oData.CreatedBy = obj.CreatedBy; objEnt.RS_District.Add(oData); objEnt.SaveChanges(); NativeDistrictResult = oData; } } result.NativeDistrict = NativeDistrictResult != null && NativeDistrictResult.DistrictId != 0 ? NativeDistrictResult.DistrictId : (int?)null; } using (RSEntities objEnt = new RSEntities()) { if (obj.NativeLocationName.Trim() != string.Empty) { /// Checking for current location present or not var CurrentLocation = objEnt.RS_Location.Where(o => o.LocationName.Trim().ToUpper() == obj.NativeLocationName.Trim().ToUpper()); if (CurrentLocation.Count() > 0) { NativeLocationResult = CurrentLocation.FirstOrDefault(); } else { RS_Location oData = new RS_Location(); oData.LocationName = obj.NativeLocationName; oData.DistrictId = NativeDistrictResult.DistrictId; oData.CreatedOn = DateTime.Now; oData.CreatedBy = obj.CreatedBy; objEnt.RS_Location.Add(oData); objEnt.SaveChanges(); NativeLocationResult = oData; } } result.NativeLocation = NativeLocationResult != null && NativeLocationResult.LocationId != 0 ? NativeLocationResult.LocationId : (int?)null; } return(result); }