public ApiResult <List <NhiemVuKetQua> > AddNhiemVuKetQuas(List <NhiemVuKetQuaViewModel> nhiemVuKetQuaViewModels) { var nhiemVuKetQuas = new List <NhiemVuKetQua>(); var mapper = new NhiemVuKetQuaMapper(); foreach (var src in nhiemVuKetQuaViewModels) { var des = new NhiemVuKetQua(); mapper.NhiemVuKetQuaViewModelToNhiemVuKetQua(src, des); nhiemVuKetQuas.Add(des); } try { var db = new BCDHTBContext(); db.NhiemVuKetQuas.AddRange(nhiemVuKetQuas); db.SaveChanges(); return(new ApiResult <List <NhiemVuKetQua> > { data = null, total = nhiemVuKetQuas.Count, err = new Error { code = "201", internalMessage = "", userMessage = "" } }); } catch (Exception ex) { return(new ApiResult <List <NhiemVuKetQua> > { data = null, total = 0, err = new Error { code = "500", internalMessage = ex.ToString(), userMessage = "" } }); } }
public void NhiemVuKetQuaViewModelToNhiemVuKetQua(NhiemVuKetQuaViewModel source, NhiemVuKetQua destination) { if (source is null) { throw new ArgumentNullException(nameof(source)); } if (destination is null) { throw new ArgumentNullException(nameof(destination)); } destination.DonViXuLy = source.DonViXuLy; destination.IdVanBan = source.IdVanBan; destination.LoaiVanBan = source.LoaiVanBan; destination.NguoiKy = source.NguoiKy; destination.NguoiXuLy = source.NguoiXuLy; destination.SoKiHieu = source.SoKiHieu; destination.TrichYeu = source.TrichYeu; }