public async Task <ActionResult <AdvertTypes> > PostAdvertTypes(AdvertTypes advertTypes) { _context.AdvertTypes.Add(advertTypes); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAdvertTypes", new { id = advertTypes.Id }, advertTypes)); }
//was: public async Task<IActionResult> PutAdvertTypes(int id, AdvertTypes advertTypes) public async Task <ActionResult <AdvertTypes> > PutAdvertTypes(int id, AdvertTypes advertTypes) { if (id != advertTypes.Id) { return(BadRequest()); } _context.Entry(advertTypes).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdvertTypesExists(id)) { return(NotFound()); } else { throw; } } return(advertTypes); //return NoContent(); // was }
public async void PutAdvertType_Put() { var query = new AdvertTypesController(context); var newAdvertType = new AdvertTypes { Id = 3, Type = "Cars", TypeDescription = "Fast" }; // https://stackoverflow.com/questions/36856073/the-instance-of-entity-type-cannot-be-tracked-because-another-instance-of-this-t/42475617 var local = context.AdvertTypes.Local.Where(t => t.Id == 3).FirstOrDefault(); if (local != null) { context.Entry(local).State = EntityState.Detached; // only needed for xUnit testing } var result = await query.PutAdvertTypes(3, newAdvertType); // async var added = await query.GetAdvertTypes(3); // async Assert.Equal(newAdvertType.Type, added.Value.Type); Assert.Equal(newAdvertType.TypeDescription, added.Value.TypeDescription); Assert.Equal(newAdvertType.Id, added.Value.Id); Assert.Equal(newAdvertType, added.Value); Assert.Equal(newAdvertType, result.Value); }
public async void PostAdvertTypes_Returns_OK() { var query = new AdvertTypesController(context); var newAdvertType = new AdvertTypes { Id = 4, Type = "Bikes", TypeDescription = "Fast" }; var result = await query.PostAdvertTypes(newAdvertType); // async Assert.IsType <ActionResult <AdvertTypes> >(result); Assert.IsType <CreatedAtActionResult>(result.Result); }
public async void PostAdvertType_Add() { var query = new AdvertTypesController(context); var newAdvertType = new AdvertTypes { Id = 4, Type = "Bikes", TypeDescription = "Fast" }; var result = await query.PostAdvertTypes(newAdvertType); // async var added = await query.GetAdvertTypes(4); // async Assert.Equal(newAdvertType.Type, added.Value.Type); Assert.Equal(newAdvertType.TypeDescription, added.Value.TypeDescription); Assert.Equal(newAdvertType.Id, added.Value.Id); Assert.Equal(newAdvertType, added.Value); //Assert.Equal(newAdvertType, result.Value); // ?? }
public List <ResultModel> PopulateResultModel(List <string> splittedInput, AdvertTypes advertType, int searchMasterID, List <ResultModel> advertIDList, out List <int> advertWebList) { List <ResultModel> ResultModelList = new List <ResultModel>(); int advertID; bool IsReaLEstate = advertType == AdvertTypes.RealEstate; advertWebList = new List <int>(); string AttributesContent; List <string> ResultAttribute = new List <string>(); foreach (var item in splittedInput) { if (IsReaLEstate) { AttributesContent = TrimHelper(HTMLCriteriaClass.AttributeTrimCriteria, item).Replace(" ", ""); ResultAttribute = SplitDivisionHelper(HTMLCriteriaClass.ResultAttributeDivisionCriteria, AttributesContent, true); } advertID = Convert.ToInt32(GetDataFromSplittedHTML(HTMLCriteriaClass.AdvertIDCriteria, item)); advertWebList.Add(advertID); if (!advertIDList.Any(n => n.AdvertID == advertID)) { ResultModel Addition = new ResultModel { AdvertDate = ConvertToDateTime(GetDataFromSplittedHTML(HTMLCriteriaClass.DateCriteria, item).Replace("</span>\n <br/>\n <span>", " ")), Description = GetDataFromSplittedHTML(HTMLCriteriaClass.DescriptionCriteria, item), AdvertID = advertID, Location = GetDataFromSplittedHTML(HTMLCriteriaClass.LocationCriteria, item).Replace("<br/>", " - "), Price = Convert.ToInt32(GetDataFromSplittedHTML(HTMLCriteriaClass.PriceCriteria, item).Replace(".", "").Replace(" TL", "")), SearchMasterID = searchMasterID, ThumbnailLink = GetDataFromSplittedHTML(HTMLCriteriaClass.ThumbnailCriteria, item), Size = IsReaLEstate ? Convert.ToInt32(ResultAttribute[0]) : 0, Room = IsReaLEstate ? ResultAttribute[1] : "", Heating = IsReaLEstate ? ResultAttribute[2] : "" }; ResultModelList.Add(Addition); } } return(ResultModelList); }