예제 #1
0
        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));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
        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));
        }
예제 #5
0
        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));
        }
예제 #6
0
 public void Update(GiongThuCung giongThuCung)
 {
     _giongThuCungRepository.Update(giongThuCung);
 }
예제 #7
0
 public GiongThuCung Add(GiongThuCung giongThuCung)
 {
     return(_giongThuCungRepository.Add(giongThuCung));
 }