public async Task <IHttpActionResult> PutContactType(int contactTypeId, ContactTypeDTO value) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (value.ContactTypeId != contactTypeId) { return(BadRequest()); } DbContext.Entry(value).State = EntityState.Modified; try { await DbContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ValueExists(contactTypeId)) { return(NotFound()); } throw; } return(StatusCode(HttpStatusCode.NoContent)); } catch (Exception ex) { Log.Error("ContactType.Put: " + ex); throw; } }
public static ContactType ReadFromDTO(ContactType target, ContactTypeDTO source) { target.ContactTypeId = source.ContactTypeId; target.Type = source.Type; target.ModifiedDate = source.ModifiedDate; return(target); }
private ContactType DataDTOToModel(ContactTypeDTO dataDto) { return(new ContactType() { ContactTypeId = dataDto.Id, ContactTypeName = dataDto.Name }); }
public IHttpActionResult GetContactType(int id) { ContactTypeDTO contactType = _contactTypeService.GetById(id); if (contactType == null) { return(NotFound()); } return(Ok(contactType)); }
public static int Compare(ContactType lhs, ContactTypeDTO rhs) { if (ReferenceEquals(lhs, null)) { return(-1); } if (ReferenceEquals(rhs, null)) { return(1); } return(lhs.ContactTypeId.CompareTo(lhs.ContactTypeId)); }
public IHttpActionResult DeleteContactType(int id) { ContactTypeDTO contactType = _contactTypeService.GetById(id); if (contactType == null) { return(NotFound()); } else { _contactTypeService.Delete(id); return(Ok(contactType)); } }
private ContactTypeDTO MapToContactTypeDTO(IDictionary <string, Object> dictionary) { var ContactTypeId = dictionary["KODEID"]; var ContactTypeName = dictionary["LANGTNAVN"]; ContactTypeDTO dto = new ContactTypeDTO(); if (ContactTypeId != null) { dto.Id = (long)ContactTypeId; } if (ContactTypeName != null) { dto.Name = ContactTypeName.ToString(); } return(dto); }
public async Task <IHttpActionResult> PostContactType(ContactTypeDTO value) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DbContext.ContactTypes.Add(ContactTypeTX.ReadFromDTO(new ContactType(), value)); await DbContext.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { ContactTypeId = value.ContactTypeId }, value)); } catch (Exception ex) { Log.Error("ContactType.Post: " + ex); throw; } }
public async Task <IHttpActionResult> GetContactType(int contactTypeId) { try { ContactTypeDTO found = await Task.Run(() => { return(ContactTypeTX.WriteToDTO(DbContext.ContactTypes .AsEnumerable().FirstOrDefault(e => e.ContactTypeId == contactTypeId))); }); if (found == null) { return(NotFound()); } return(Ok(found)); } catch (Exception ex) { Log.Error("ContactType.Get: " + ex); throw; } }
public static int Compare(ContactTypeDTO lhs, ContactType rhs) { return(Compare(rhs, lhs) * -1); }
public ContactType Map(ContactTypeDTO dto) { if (dto == null) return null; var contactType = Mapper.Map<ContactTypeDTO, ContactType>(dto); return contactType; }