public HttpResponseMessage KhoaMo(HttpRequestMessage request, int id) { GiongThuCung modelGiongThuCung = null; try { _giongThuCungService.KhoaMo(id); _giongThuCungService.SaveChange(); modelGiongThuCung = _giongThuCungService.GetById(id); if (modelGiongThuCung != null) { if (modelGiongThuCung.TrangThai != null && (bool)modelGiongThuCung.TrangThai) { Message = "Mở giống thú cưng thành công"; } else { Message = "Khóa giống thú cưng thành công"; } } else { throw new DbEntityValidationException("Khóa mở giống thú cưng không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelGiongThuCung)); }
public HttpResponseMessage UploadImage(HttpRequestMessage request) { GiongThuCung modelGiongThuCung = null; try { var httpRequest = HttpContext.Current.Request; //Upload Image var postedFile = httpRequest.Files["Image"]; var id = httpRequest["Id"]; var giong = _giongThuCungService.GetById(int.Parse(id)); //Create custom filename if (postedFile != null) { var imageName = new String(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()) .Replace(" ", "-"); imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName); var filePath = HttpContext.Current.Server.MapPath("~/Images/" + imageName); postedFile.SaveAs(filePath); giong.HinhAnh = imageName; _giongThuCungService.Update(giong); _giongThuCungService.SaveChange(); modelGiongThuCung = _giongThuCungService.GetById(giong.IdGiongThuCung); } if (modelGiongThuCung != null) { Message = "Upload ảnh thành công thành công"; } else { throw new DbEntityValidationException("Upload ảnh không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelGiongThuCung)); }
public HttpResponseMessage GetById(HttpRequestMessage request, int id) { GiongThuCung giongThuCungSingler = null; try { giongThuCungSingler = _giongThuCungService.GetById(id); if (giongThuCungSingler != null) { Message = "Thông tin giống thú cưng với id: " + id; } else { throw new DbEntityValidationException(string.Format("Không tìm kiếm được giống thú cưng với id {0}", id)); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, giongThuCungSingler)); }
public HttpResponseMessage Create(HttpRequestMessage request, GiongThuCung giongThuCung) { GiongThuCung modelGiongThuCung = null; try { modelGiongThuCung = _giongThuCungService.Add(giongThuCung); if (modelGiongThuCung != null) { Message = "Tạo mới giống thú cưng thành công"; _giongThuCungService.SaveChange(); } else { throw new DbEntityValidationException("tạo giống thú cưng không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelGiongThuCung)); }
public HttpResponseMessage Update(HttpRequestMessage request, GiongThuCung giongThuCung) { GiongThuCung modelGiongThuCung = null; try { _giongThuCungService.Update(giongThuCung); _giongThuCungService.SaveChange(); modelGiongThuCung = _giongThuCungService.GetById(giongThuCung.IdGiongThuCung); if (modelGiongThuCung != null) { Message = "Cập nhật thông tin thành công"; } else { throw new DbEntityValidationException("Cập nhật thông tin không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelGiongThuCung)); }
public void Update(GiongThuCung giongThuCung) { _giongThuCungRepository.Update(giongThuCung); }
public GiongThuCung Add(GiongThuCung giongThuCung) { return(_giongThuCungRepository.Add(giongThuCung)); }