public IActionResult TaoNhiemVu() { var id = Database.NhiemVus.Any() ? Database.NhiemVus.Max(n => n.Id) + 1 : 1; var nhiemVu = new NhiemVu { Id = id, CanBoId = 1, DonViId = 1, TrangThai = TrangThaiNhiemVu.ChoThucHien }; nhiemVu.WorkflowId = _host.StartWorkflow(nameof(NhiemVuWorkflow), new NhiemVuData { NhiemVuId = nhiemVu.Id, TrangThai = TrangThaiNhiemVu.ChoThucHien }).GetAwaiter().GetResult(); // terminate workflow if adding db error Database.NhiemVus.Add(nhiemVu); Database.PhanXuLyNhiemVus.Add(new PhanXuLyNhiemVu { Id = 1, CanBoId = 1, DonViId = 1, NhiemVuId = id, VaiTroXuLy = VaiTroXuLy.ChuTri, TrangThai = TrangThaiPhanXuLy.DangThucHien, WorkflowId = nhiemVu.WorkflowId }); _logger.LogInformation($"============ Started workflow {nhiemVu.WorkflowId} for Nhiem vu {id} ============"); return(Ok()); }
public IActionResult Post2([FromBody] NhiemVu cb, string id) { try{ NhiemVu edit = _db.NhiemVu.FirstOrDefault(x => x.MaNhiemVu == id); edit.TenNhiemVu = cb.TenNhiemVu; _db.SaveChanges(); return(Ok("Them thanh cong")); } catch { return(BadRequest()); } }
public IActionResult Post3(string id) { try{ NhiemVu del = _db.NhiemVu.FirstOrDefault(x => x.MaNhiemVu == id); del.TrangThai = false; _db.SaveChanges(); return(Ok("Xoa thanh cong")); } catch { return(BadRequest()); } }
public void NhiemVuViewModelToNhiemVu(NhiemVuViewModel source, NhiemVu 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.NguoiPhuTrach = source.NguoiPhuTrach; destination.SoKyHieu = source.SoKyHieu; destination.TenNhiemVu = source.TenNhiemVu; destination.TrichYeu = source.TrichYeu; try { destination.NgayBanHanh = DateTime.Parse(source.NgayBanHanh); } catch (Exception) { destination.NgayBanHanh = null; } try { destination.NgayBaoCao = DateTime.Parse(source.NgayBaoCao); } catch (Exception) { destination.NgayBaoCao = null; } try { destination.NgayXuLy = DateTime.Parse(source.NgayXuLy); } catch (Exception) { destination.NgayXuLy = null;; } }
public ApiResult <List <NhiemVu> > AddNhiemVus(List <NhiemVuViewModel> nhiemVuViewModels) { var nhiemVus = new List <NhiemVu>(); var mapper = new NhiemVuMapper(); foreach (var src in nhiemVuViewModels) { var des = new NhiemVu(); mapper.NhiemVuViewModelToNhiemVu(src, des); nhiemVus.Add(des); } try { var db = new BCDHTBContext(); db.NhiemVus.AddRange(nhiemVus); db.SaveChanges(); return(new ApiResult <List <NhiemVu> > { data = null, total = nhiemVus.Count, err = new Error { code = "201", internalMessage = "", userMessage = "" } }); } catch (Exception ex) { return(new ApiResult <List <NhiemVu> > { data = null, total = 0, err = new Error { code = "500", internalMessage = ex.ToString(), userMessage = "" } }); } }
public IActionResult Post([FromBody] NhiemVu cb) { cb.TrangThai = true; try { NhiemVu tour = new NhiemVu() { MaNhiemVu = cb.MaNhiemVu, TenNhiemVu = cb.TenNhiemVu, TrangThai = cb.TrangThai }; _db.NhiemVu.Add(tour); _db.SaveChanges(); return(Ok("Them thanh cong")); } catch (Exception) { return(BadRequest()); } }