public HttpResponseMessage Delete(HttpRequestMessage request, int id) { CoSoThuY modelCoSoThuY = null; try { modelCoSoThuY = _coSoThuYService.GetById(id); if (modelCoSoThuY.IdTaiKhoan != null) { _taiKhoanService.Delete((int)modelCoSoThuY.IdTaiKhoan); } _coSoThuYService.SaveChange(); modelCoSoThuY = _coSoThuYService.Delete(id); _coSoThuYService.SaveChange(); if (modelCoSoThuY != null) { Message = "Xóa cơ sở thú y thành công"; } else { throw new DbEntityValidationException("Xóa cơ sở thú y không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelCoSoThuY)); }
public HttpResponseMessage KhoaMo(HttpRequestMessage request, int id) { CoSoThuY modelCoSoThuY = null; try { _coSoThuYService.KhoaMo(id); _coSoThuYService.SaveChange(); modelCoSoThuY = _coSoThuYService.GetById(id); if (modelCoSoThuY != null) { if (modelCoSoThuY.TrangThai != null && (bool)modelCoSoThuY.TrangThai) { Message = "Mở cơ sở thú y thành công"; } else { Message = "Khóa cơ sở thú y thành công"; } } else { throw new DbEntityValidationException("Khóa mở cơ sở thú y không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelCoSoThuY)); }
public HttpResponseMessage Create(HttpRequestMessage request, CoSoThuY coSoThuY) { CoSoThuY modelCoSoThuY = null; try { var tenTaiKhoan1 = coSoThuY.TenCoSoThuY.ToLower(); var tenTaiKhoan2 = _coSoThuYService.ThayDoiChuoi(tenTaiKhoan1); var tenTaiKhoan3 = tenTaiKhoan2.Replace(" ", ""); var pass = coSoThuY.SDT.Substring(6); var taikhoan = new TaiKhoan { UserName = tenTaiKhoan3, Pass = pass, IdQuyen = 2, TrangThai = true, }; var taiKhoan = _taiKhoanService.Add(taikhoan); _coSoThuYService.SaveChange(); if (taiKhoan.IdTaiKhoan != 0) { coSoThuY.IdTaiKhoan = taikhoan.IdTaiKhoan; modelCoSoThuY = _coSoThuYService.Add(coSoThuY); _coSoThuYService.SaveChange(); if (modelCoSoThuY != null) { Message = "Tạo mới người dùng và tài khoản thành công thành công"; _taiKhoanService.SaveChange(); } } if (modelCoSoThuY != null) { var gioiThieu = new GioiThieu() { IdCoSoThuY = modelCoSoThuY.IdCoSoThuY, NoiDung = "Phần giới thiệu của cơ sở thú y ở đây", }; _gioiThieuService.Add(gioiThieu); _coSoThuYService.SaveChange(); Message = "Tạo mới cơ sở thú y thành công"; } else { throw new DbEntityValidationException("tạo mới cơ sở thú y không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelCoSoThuY)); }
public HttpResponseMessage GetByIdTaiKhoan(HttpRequestMessage request, int id) { CoSoThuY coSoThuYSingler = null; try { coSoThuYSingler = _coSoThuYService.GetByIdTaiKhoan(id); if (coSoThuYSingler != null) { Message = "Thông tin cơ sở thú y với id: " + id; } else { throw new DbEntityValidationException(string.Format("Không tìm kiếm được cơ sở thú y với id {0}", id)); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, coSoThuYSingler)); }
public HttpResponseMessage Update(HttpRequestMessage request, CoSoThuY manNang) { CoSoThuY modelCoSoThuY = null; try { _coSoThuYService.Update(manNang); _coSoThuYService.SaveChange(); modelCoSoThuY = _coSoThuYService.GetById(manNang.IdCoSoThuY); if (modelCoSoThuY != null) { Message = "Sửa thông tin cơ sở thú y thành công"; } else { throw new DbEntityValidationException("sửa thông tin cơ sở thú y không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelCoSoThuY)); }
public void Update(CoSoThuY coSoThuY) { _coSoThuYRepository.Update(coSoThuY); }
public CoSoThuY Add(CoSoThuY coSoThuY) { return(_coSoThuYRepository.Add(coSoThuY)); }