public async Task <ThongBaoViewModel> GetByIdAsync(string id) { ThongBaoViewModel result = await _db.ThongBaos .Where(x => x.ThongBaoId == id) .ProjectTo <ThongBaoViewModel>(_mp.ConfigurationProvider) .FirstOrDefaultAsync(); return(result); }
public static void UpdateThongBao(this ThongBao thongbao, ThongBaoViewModel thongbaoVM) { thongbao.Id = thongbaoVM.Id; thongbao.TieuDe = thongbaoVM.TieuDe; thongbao.NoiDung = thongbaoVM.NoiDung; thongbao.NguoiTao = thongbaoVM.NguoiTao; thongbao.MoreFile = thongbaoVM.MoreFile; thongbao.Created_at = thongbaoVM.Created_at; thongbao.Updated_at = thongbaoVM.Updated_at; }
public async Task <ThongBaoViewModel> CreateAsync(ThongBaoViewModel viewModel) { ThongBao model = _mp.Map <ThongBao>(viewModel); await _db.ThongBaos.AddAsync(model); await _db.SaveChangesAsync(); ThongBaoViewModel result = _mp.Map <ThongBaoViewModel>(model); return(result); }
public async Task <IActionResult> GetDetail(string id) { if (string.IsNullOrEmpty(id)) { return(BadRequest()); } ThongBaoViewModel data = await _thongBaoService.GetDetailAsync(id); if (data == null) { return(NotFound()); } return(Ok(data)); }
public async Task <IActionResult> Create(ThongBaoViewModel viewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { ThongBaoViewModel result = await _thongBaoService.CreateAsync(viewModel); return(CreatedAtAction(nameof(GetById), new { id = result.ThongBaoId }, result)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public HttpResponseMessage Updated(HttpRequestMessage resquest, ThongBaoViewModel thongBaoVM) { return(CreateReponse(resquest, () => { if (!ModelState.IsValid) { return resquest.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { var thongbao = _thongBaoService.GetById(thongBaoVM.Id);; thongbao.UpdateThongBao(thongBaoVM); thongbao.NguoiTao = User.Identity.Name; _thongBaoService.Update(thongbao); _thongBaoService.save(); return resquest.CreateResponse(HttpStatusCode.Created, thongBaoVM); } })); }
public HttpResponseMessage Created(HttpRequestMessage resquest, ThongBaoViewModel thongBaoVM) { return(CreateReponse(resquest, () => { if (!ModelState.IsValid) { return resquest.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { var thongbao = new ThongBao(); thongbao.UpdateThongBao(thongBaoVM); thongbao.NguoiTao = User.Identity.Name; thongbao.Created_at = DateTime.Now; var responData = _thongBaoService.Add(thongbao); _thongBaoService.save(); return resquest.CreateResponse(HttpStatusCode.Created, thongBaoVM); } })); }
public async Task <ThongBaoViewModel> GetDetailAsync(string id) { ThongBao model = await _db.ThongBaos.FirstOrDefaultAsync(x => x.ThongBaoId == id); if (model.IsRead == false) { model.IsRead = true; model.IsOpend = true; await _db.SaveChangesAsync(); } ThongBaoViewModel result = _mp.Map <ThongBaoViewModel>(model); //if (result.LoaiThongBao == LoaiThongBao.HoaDonXuatChoDNRuiRo) //{ // if (!string.IsNullOrEmpty(result.ObjectId)) // { // result.HoaDon = await _db.HoaDons // .Include(x => x.HoaDonFile) // .Where(x => x.HoaDonId == result.ObjectId) // .ProjectTo<HoaDonViewModel>(_mp.ConfigurationProvider) // .FirstOrDefaultAsync(); // if (!string.IsNullOrEmpty(result.HoaDon.MaSoThueNguoiMua)) // { // result.DoanhNghiep = await _db.DoanhNghieps // .Where(x => x.MaSoThue == result.HoaDon.MaSoThueNguoiMua) // .ProjectTo<DoanhNghiepViewModel>(_mp.ConfigurationProvider) // .FirstOrDefaultAsync(); // result.DoanhNghiep.TenLoaiDoanhNghiep = result.DoanhNghiep.LoaiDoanhNghiep.GetDescription(); // result.DoanhNghiep.TenTrangThai = result.DoanhNghiep.TrangThai.GetDescription(); // } // } //} return(result); }