public async Task <HttpResponseMessage> GetAllByIdAsync(PageSettingModel _params)
        {
            var Res    = Request.CreateResponse();
            var Result = new Res();

            try
            {
                var data = await Task.Run(() => _pageSettingService.GetById(_params));

                if (data != null)
                {
                    Result.Data       = data;
                    Result.Status     = true;
                    Result.Message    = "Call API Success";
                    Result.StatusCode = HttpStatusCode.OK;
                }
                else
                {
                    Result.Data       = null;
                    Result.Status     = false;
                    Result.Message    = "Không tìm thấy dữ liệu";
                    Result.StatusCode = HttpStatusCode.InternalServerError;
                }
                Res.Content = new StringContent(JsonConvert.SerializeObject(Result));
                return(Res);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public async Task <HttpResponseMessage> DeleteAsync(PageSettingModel _param)
        {
            var Res    = Request.CreateResponse();
            var Result = new Res();

            try
            {
                if (_param != null)
                {
                    await Task.Run(() => _pageSettingService.Delete(_param));

                    Result.Status     = true;
                    Result.Message    = "Xóa thành công";
                    Result.StatusCode = HttpStatusCode.OK;
                }
                else
                {
                    Result.Status     = false;
                    Result.Message    = "Xóa thất bại";
                    Result.StatusCode = HttpStatusCode.BadRequest;
                }
                Res.Content = new StringContent(JsonConvert.SerializeObject(Result));
                return(Res);
            }
            catch (Exception ex)
            {
                Result.Status     = false;
                Result.Message    = "Có lỗi xảy ra trong quá trình xóa " + ex.Message;
                Result.StatusCode = HttpStatusCode.BadRequest;
                throw new Exception(ex.Message);
            }
        }
Beispiel #3
0
        /*===Get All By Id*/
        public PageSettingModel GetById(PageSettingModel _params)
        {
            var data = _uow.PageSettingRepo.SQLQuery <PageSettingModel>("sp_PageSetting_GetAllById " +
                                                                        "@PageSetting_ID",
                                                                        new SqlParameter("PageSetting_ID", SqlDbType.Int)
            {
                Value = _params.PageSetting_ID
            }).FirstOrDefault();

            return(data);
        }
Beispiel #4
0
        /*===Delete===*/
        public void Delete(PageSettingModel _params)
        {
            try
            {
                _uow.PageSettingRepo.ExcQuery("exec sp_PageSetting_Delete " +
                                              "@PageSetting_ID"

                                              ,
                                              new SqlParameter("PageSetting_ID", SqlDbType.Int)
                {
                    Value = _params.PageSetting_ID
                }
                                              );
            }
            catch (Exception ex)
            {
                throw new Exception("Có lỗi xảy ra trong quá trình xóa" + ex.Message);
            }
        }
Beispiel #5
0
        /*===Insert===*/
        public void Insert(PageSettingModel _params)
        {
            try
            {
                _uow.PageSettingRepo.ExcQuery("exec sp_PageSetting_Insert " +
                                              "@PageSetting_NameVN," +
                                              "@PageSetting_NameEN, " +
                                              "@PageSetting_UrlOut," +
                                              "@PageSetting_Rewrite," +
                                              "@PageSetting_SearchVN," +
                                              "@PageSetting_SearchEN," +
                                              "@PageSetting_Img," +
                                              "@Img_Width," +
                                              "@Img_Unit_Width," +
                                              "@Img_Height," +
                                              "@Img_Unit_Height," +
                                              "@Keyword_Titile," +
                                              "@Keyword_Content," +
                                              "@Keyword_Description," +
                                              "@CreateDate," +
                                              "@CreateBy," +
                                              "@UpdateDate," +
                                              "@UpdateBy," +
                                              "@Lock," +
                                              "@Is_Active," +
                                              "@Is_TopPage," +
                                              "@Is_LeftPage," +
                                              "@Is_RightPage," +
                                              "@Is_BottomPage," +
                                              "@Display_Order"

                                              ,
                                              new SqlParameter("PageSetting_NameVN", SqlDbType.NVarChar, (50))
                {
                    Value = _params.PageSetting_NameVN
                },
                                              new SqlParameter("PageSetting_NameEN", SqlDbType.NVarChar, (50))
                {
                    Value = _params.PageSetting_NameEN
                },
                                              new SqlParameter("PageSetting_UrlOut", SqlDbType.NVarChar, (255))
                {
                    Value = _params.PageSetting_UrlOut ?? DBNull.Value.ToString()
                },
                                              new SqlParameter("PageSetting_Rewrite", SqlDbType.NVarChar, (255))
                {
                    Value = _params.PageSetting_Rewrite
                },
                                              new SqlParameter("PageSetting_SearchVN", SqlDbType.VarChar, (50))
                {
                    Value = _params.PageSetting_SearchVN ?? DBNull.Value.ToString()
                },
                                              new SqlParameter("PageSetting_SearchEN", SqlDbType.VarChar, (50))
                {
                    Value = _params.PageSetting_SearchEN ?? DBNull.Value.ToString()
                },
                                              new SqlParameter("PageSetting_Img", SqlDbType.VarChar)
                {
                    Value = _params.PageSetting_Img ?? DBNull.Value.ToString()
                },
                                              new SqlParameter("Img_Width", SqlDbType.Int)
                {
                    Value = _params.Img_Width ?? 0
                },
                                              new SqlParameter("Img_Unit_Width", SqlDbType.VarChar, (10))
                {
                    Value = _params.Img_Unit_Width ?? DBNull.Value.ToString()
                },
                                              new SqlParameter("Img_Height", SqlDbType.Int)
                {
                    Value = _params.Img_Height ?? 0
                },
                                              new SqlParameter("Img_Unit_Height", SqlDbType.VarChar, (10))
                {
                    Value = _params.Img_Unit_Height ?? DBNull.Value.ToString()
                },
                                              new SqlParameter("Keyword_Titile", SqlDbType.NVarChar, (50))
                {
                    Value = _params.Keyword_Titile ?? DBNull.Value.ToString()
                },
                                              new SqlParameter("Keyword_Content", SqlDbType.NVarChar)
                {
                    Value = _params.Keyword_Content ?? DBNull.Value.ToString()
                },
                                              new SqlParameter("Keyword_Description", SqlDbType.NVarChar)
                {
                    Value = _params.Keyword_Description ?? DBNull.Value.ToString()
                },
                                              new SqlParameter("CreateDate", SqlDbType.Date)
                {
                    Value = _params.CreateDate == null ? DateTime.Now : _params.CreateDate
                },
                                              new SqlParameter("CreateBy", SqlDbType.Int)
                {
                    Value = _params.CreateBy == null ? 1 : _params.CreateBy
                },
                                              new SqlParameter("UpdateDate", SqlDbType.Date)
                {
                    Value = _params.UpdateDate == null ? DateTime.Now : _params.UpdateDate
                },
                                              new SqlParameter("UpdateBy", SqlDbType.Int)
                {
                    Value = _params.UpdateBy == null ? 1 : _params.UpdateBy
                },
                                              new SqlParameter("Lock", SqlDbType.Int)
                {
                    Value = _params.Lock ?? 0
                },
                                              new SqlParameter("Is_Active", SqlDbType.Bit)
                {
                    Value = _params.Is_Active == null ? true : _params.Is_Active
                },
                                              new SqlParameter("Is_TopPage", SqlDbType.Bit)
                {
                    Value = _params.Is_TopPage == null ? true : _params.Is_TopPage
                },
                                              new SqlParameter("Is_BottomPage", SqlDbType.Bit)
                {
                    Value = _params.Is_BottomPage == null ? true : _params.Is_BottomPage
                },
                                              new SqlParameter("Is_LeftPage", SqlDbType.Bit)
                {
                    Value = _params.Is_LeftPage == null ? false : _params.Is_LeftPage
                },
                                              new SqlParameter("Is_RightPage", SqlDbType.Bit)
                {
                    Value = _params.Is_RightPage == null ? false : _params.Is_RightPage
                },
                                              new SqlParameter("Display_Order", SqlDbType.Int)
                {
                    Value = _params.Display_Order == null ? 1 : _params.Display_Order
                }
                                              );
            }
            catch (Exception ex)
            {
                throw new Exception("Có lỗi xảy ra trong quá trình thêm mới" + ex.Message);
            }
        }
        public async Task <HttpResponseMessage> UpdateAsync(PageSettingModel _params)
        {
            var Res           = Request.CreateResponse();
            var Result        = new Res();
            var query         = _pageSettingService.GetById(_params);
            var StatusUpload  = false;
            var MessageUpload = string.Empty;
            var OutputFile    = string.Empty;

            try
            {
                if (_params != null)
                {
                    if (string.IsNullOrEmpty(_params.PageSetting_NameVN))
                    {
                        Result.Status     = false;
                        Result.Message    = "Tiêu đề tiếng việt không được trống " + _params.PageSetting_NameVN;
                        Result.StatusCode = HttpStatusCode.BadRequest;
                    }
                    else if (string.IsNullOrEmpty(_params.PageSetting_NameEN))
                    {
                        Result.Status     = false;
                        Result.Message    = "Tên tiêu đề tiếng anh không được trống " + _params.PageSetting_NameEN;
                        Result.StatusCode = HttpStatusCode.BadRequest;
                    }
                    else if (string.IsNullOrEmpty(_params.PageSetting_Rewrite))
                    {
                        Result.Status     = false;
                        Result.Message    = "Đường dẫn thân thiện không được trống " + _params.PageSetting_Rewrite;
                        Result.StatusCode = HttpStatusCode.BadRequest;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(_params.ImageBase64))
                        {
                            _params.PageSetting_Img = query.PageSetting_Img;
                            await Task.Run(() => _pageSettingService.Update(_params));

                            Result.Status     = true;
                            Result.Message    = "Cập nhập thành công";
                            Result.StatusCode = HttpStatusCode.OK;
                        }
                        else
                        {
                            //Viet ham upload vao day
                            UploadImageWithOutResize("YouNameSystem", _params.ImageBase64, "admin", out StatusUpload, out MessageUpload, out OutputFile);
                            if (StatusUpload)
                            {
                                _params.PageSetting_Img = OutputFile;//Đường dẫn ảnh khi đã được xử lý thành ảnh
                                await Task.Run(() => _pageSettingService.Update(_params));

                                Result.Status     = true;
                                Result.Message    = "Cập nhập thành công có ảnh";
                                Result.StatusCode = HttpStatusCode.OK;
                            }
                        }
                    }
                }
                else
                {
                    Result.Status     = false;
                    Result.Message    = "Cập nhập thất bại";
                    Result.StatusCode = HttpStatusCode.BadRequest;
                }
                Res.Content = new StringContent(JsonConvert.SerializeObject(Result));
                return(Res);
            }
            catch (Exception ex)
            {
                Result.Status     = false;
                Result.Message    = "Có lỗi xảy ra trong quá trình cập nhập " + ex.Message;
                Result.StatusCode = HttpStatusCode.BadRequest;
                throw new Exception(ex.Message);
            }
        }