public HttpResponseMessage Create(HttpRequestMessage request, NganhNgheViewModel nganhNgheVm) { if (ModelState.IsValid) { try { var newNganhNghe = new NganhNghe(); newNganhNghe.UpdateNganhNghe(nganhNgheVm); newNganhNghe.CreatedDate = DateTime.Now; newNganhNghe.CreatedBy = User.Identity.Name; newNganhNghe.UpdatedDate = DateTime.Now; newNganhNghe.UpdatedBy = User.Identity.Name; _nganhNgheService.Add(newNganhNghe); _nganhNgheService.Save(); var responseData = Mapper.Map <NganhNghe, NganhNgheViewModel>(newNganhNghe); return(request.CreateResponse(HttpStatusCode.Created, responseData)); } catch (NameDuplicatedException dex) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message)); } } return(request.CreateResponse(HttpStatusCode.BadRequest, ModelState)); }
public async Task <IActionResult> Create([FromBody] NganhNghe inputModel) { try { var existTen = await _manager.FindByName(inputModel.TenNganhNghe); if (existTen != null) { throw new Exception($"Tên { MessageConst.EXIST }"); } var existMa = await _manager.FindByCode(inputModel.MaNganhNghe); if (existMa != null) { throw new Exception($"Mã { MessageConst.EXIST }"); } inputModel.NgayTao = DateTime.Now; await _manager.Create(inputModel); return(Ok()); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public void Update(NganhNghe nganhNghe) { if (_nganhNgheRepository.CheckContains(x => x.Ten == nganhNghe.Ten && x.Id != nganhNghe.Id)) { throw new NameDuplicatedException("Tên không được trùng"); } _nganhNgheRepository.Update(nganhNghe); }
public NganhNghe Add(NganhNghe nganhNghe) { if (_nganhNgheRepository.CheckContains(x => x.Ten == nganhNghe.Ten)) { throw new NameDuplicatedException("Tên không được trùng"); } return(_nganhNgheRepository.Add(nganhNghe)); }
public void EditNganhNghe(NganhNghe NN) { conn.Open(); string sql = "update NganhNghe set TenNganhNghe= @tnn where maNganhNghe= @mann"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("mnn", NN.maNganhNghe); cmd.Parameters.AddWithValue("tnn", NN.TenNganhNghe); cmd.ExecuteNonQuery(); conn.Close(); }
public bool SuaNganhNghe(NganhNghe nganhNghe) { try { var kq = db.NganhNghes.Find(nganhNghe.ID_NganhNghe); kq.TenNganhNghe = nganhNghe.TenNganhNghe; db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public static void UpdateNganhNghe(this NganhNghe nganhNghe, NganhNgheViewModel nganhNgheVm) { nganhNghe.Id = nganhNgheVm.Id; nganhNghe.Ten = nganhNgheVm.Ten; nganhNghe.Alias = nganhNgheVm.Alias; nganhNghe.ParentId = nganhNgheVm.ParentId; nganhNghe.CreatedDate = nganhNgheVm.CreatedDate; nganhNghe.CreatedBy = nganhNgheVm.CreatedBy; nganhNghe.UpdatedDate = nganhNgheVm.UpdatedDate; nganhNghe.UpdatedBy = nganhNgheVm.UpdatedBy; nganhNghe.MetaKeyword = nganhNgheVm.MetaKeyword; nganhNghe.MetaDescription = nganhNgheVm.MetaDescription; nganhNghe.Status = nganhNgheVm.Status; }
public NganhNghe get1NN(int mnn) { conn.Open(); string path = "SELECT * FROM NganhNghe WHERE maNganhNghe = " + mnn + ""; SqlCommand cmd = new SqlCommand(path, conn); NganhNghe ngN = null; SqlDataReader rd = cmd.ExecuteReader(); if (rd.Read()) { ngN = new NganhNghe(); ngN.maNganhNghe = (int)rd["maNganhNghe"]; ngN.TenNganhNghe = (string)rd["TenNganhNghe"]; } conn.Close(); return(ngN); }
public async Task <IActionResult> Delete([FromBody] NganhNghe inputModel) { try { var data = await _manager.FindById(inputModel.Id); if (data == null) { throw new Exception(MessageConst.DATA_NOT_FOUND); } data.NgaySua = DateTime.Now; data.TrangThai = 3; await _manager.Update(data); return(Ok()); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public bool LuuNganh(NganhNghe nganhNghe) { db.NganhNghes.Add(nganhNghe); db.SaveChanges(); return(true); }
public void Update(NganhNghe NganhNghe) { _nganhNgheRepository.Update(NganhNghe); }
public NganhNghe Add(NganhNghe NganhNghe) { return(_nganhNgheRepository.Add(NganhNghe)); }