public IQueryable <Interest> Query(InterestInputModel interestInputModel) { if (interestInputModel?.UserId == 0 || interestInputModel?.InterestName == null) { return(_sqlRepository.GetAll()); } return(_sqlRepository.Where(i => i.InterestName == interestInputModel.InterestName && i.UserId == interestInputModel.UserId)); }
public bool Add(InterestInputModel interestInputModel) { if (interestInputModel == null) { return(false); } if (_sqlRepository.FirstOrDefault(i => i.InterestName == interestInputModel.InterestName && i.UserId == interestInputModel.UserId) != null) { return(false); } _sqlRepository.Add(interestInputModel.MapTo <Interest>()); return(true); }
public Response Update([FromBody] InterestInputModel interestInputModel) { var response = new Response(); try { response.HttpStatusCode = _iInterestApplication.Update(interestInputModel) ? HttpStatusCode.OK : HttpStatusCode.InternalServerError; } catch (Exception ex) { response.HttpStatusCode = HttpStatusCode.InternalServerError; Console.WriteLine(ex); } return(response); }
public void AddTest() { var services = new ServiceCollection(); services.AddDbContext <SqlDbContext>(optionsBuilder => optionsBuilder.UseSqlite("Data Source=D:\\interest.db")); services.AddTransient(typeof(IRepository <,>), typeof(BaseRepository <,>)); services.AddTransient <IInterestApplication, InterestApplication>(); var serviceProvider = services.BuildServiceProvider(); var interestApplication = serviceProvider.GetService <IInterestApplication>(); var interestInputModel = new InterestInputModel { UserId = 1, InterestName = "football" }; interestApplication.Add(interestInputModel); Assert.IsTrue(interestApplication.Query(interestInputModel).Any(x => x.InterestName == "football")); }
public Response Query([FromBody] InterestInputModel interestInputModel) { var response = new Response(); try { response.HttpStatusCode = HttpStatusCode.OK; response.Result = _iInterestApplication.Query(interestInputModel); return(response); } catch (Exception ex) { Console.WriteLine(ex); response.HttpStatusCode = HttpStatusCode.InternalServerError; } return(response); }
public bool Update(InterestInputModel interestInputModel) { if (interestInputModel == null) { return(false); } var interest = _sqlRepository.FirstOrDefault(i => i.InterestName == interestInputModel.InterestName && i.UserId == interestInputModel.UserId); if (interest == null) { return(false); } _sqlRepository.Update(interestInputModel.MapTo(interest)); return(true); }