public int CreateOrUpdate(OrderBllModel order) { try { var field = _floraDbContext.Fields.FirstOrDefault(x => x.Id == order.FieldId || x.Name == order.Field.Name); var executive = _floraDbContext.Executives.FirstOrDefault(x => x.Id == order.ExecutiveId || x.Name.Equals(order.Executive.Name)); if (field == null) { throw new KeyNotFoundException(); } if (executive == null) { _executiveRepository.CreateOrUpdate(new ExecutiveBllModel { Name = order.Executive.Name }, out executive); } var entity = _mapper.Map <ExecutiveEntity>(order); order.FieldId = field.Id; order.ExecutiveId = executive.Id; _floraDbContext.Add(entity); return(_floraDbContext.SaveChanges()); } catch (Exception ex) { throw ex; } }
public IActionResult CreateOrUpdate([FromBody] ExecutiveBllModel executive) { try { return(Ok(_executiveRepository.CreateOrUpdate(executive))); } catch (Exception ex) { throw ex; } }