public async Task <ActionResult> GetParcel(int id) { ParcelForUpdateDto data = await _context.Parcels.Select(s => new ParcelForUpdateDto() { Id = s.Id, ParcelCategoryId = s.ParcelCategory.Id, Name = s.Name, Area = s.Area, CropId = s.Crops.Id }).FirstOrDefaultAsync(s => s.Id == id); return(Ok(data)); }
public async Task <ActionResult> UpdateParcel(int id, [FromBody] ParcelForUpdateDto parcel) { if (id != parcel.Id) { return(BadRequest("Idler uygun gelmir")); } var editedparcel = await _context.Parcels.FirstOrDefaultAsync(s => s.Id == id); editedparcel.ParcelCategory = await _context.ParcelCategories.FirstOrDefaultAsync(s => s.Id == parcel.ParcelCategoryId); editedparcel.Name = parcel.Name; editedparcel.Area = parcel.Area; editedparcel.Crops = await _context.Crops.FirstOrDefaultAsync(s => s.Id == parcel.CropId); _context.Entry(editedparcel).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok()); }