Пример #1
0
        public void VanBanDenViewModelToVanVanDen(VanBanDenViewModel source, VanBanDen destination)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (destination is null)
            {
                throw new ArgumentNullException(nameof(destination));
            }


            destination.CoQuanBanHanh = source.CoQuanBanHanh;
            destination.DonViNhan     = source.DonViNhan;
            destination.IdVanBan      = source.IdVanBan;
            destination.SoKyHieu      = source.SoKyHieu;
            destination.TrangThai     = source.TrangThai;
            destination.TrichYeu      = source.TrichYeu;

            try
            {
                destination.NgayBanHanh = DateTime.Parse(source.NgayBanHanh);
            }
            catch (Exception)
            {
                destination.NgayBanHanh = null;
            }

            try
            {
                destination.NgayNhan = DateTime.Parse(source.NgayNhan);
            }
            catch (Exception)
            {
                destination.NgayNhan = null;
            }

            try
            {
                destination.NgayXuLyXong = DateTime.Parse(source.NgayXuLyXong);
            }
            catch (Exception)
            {
                destination.NgayXuLyXong = null;
            }
        }
Пример #2
0
        public ApiResult <List <VanBanDen> > AddVanBanDens(List <VanBanDenViewModel> vanBanDenViewModels)
        {
            var vanBanDens = new List <VanBanDen>();
            var mapper     = new VanBanDenMapper();

            foreach (var src in vanBanDenViewModels)
            {
                var des = new VanBanDen();
                mapper.VanBanDenViewModelToVanVanDen(src, des);

                vanBanDens.Add(des);
            }

            try
            {
                var db = new BCDHTBContext();
                db.VanBanDens.AddRange(vanBanDens);
                db.SaveChanges();

                return(new ApiResult <List <VanBanDen> >
                {
                    data = null,
                    total = vanBanDens.Count,
                    err = new Error
                    {
                        code = "201",
                        internalMessage = "",
                        userMessage = ""
                    }
                });
            }
            catch (Exception ex)
            {
                return(new ApiResult <List <VanBanDen> >
                {
                    data = null,
                    total = 0,
                    err = new Error
                    {
                        code = "500",
                        internalMessage = ex.ToString(),
                        userMessage = ""
                    }
                });
            }
        }