Beispiel #1
0
        public IHttpActionResult RetrieveData(int id)
        {
            ApiResData res = new ApiResData();

            try
            {
                TOURIS_TM_CATEGORY category     = repo.Retrieve(id);
                TOURIS_TV_CATEGORY categoryView = new TOURIS_TV_CATEGORY();

                if (category != null)
                {
                    categoryView.ID                   = category.ID;
                    categoryView.CATEGORY_CODE        = category.CATEGORY_CODE;
                    categoryView.CATEGORY_NAME        = category.CATEGORY_NAME;
                    categoryView.CATEGORY_DESCRIPTION = category.CATEGORY_DESCRIPTION;
                    categoryView.URL                  = category.URL;
                    categoryView.CLASS                = category.CLASS;
                    categoryView.PHOTO_PATH           = category.PHOTO_PATH;
                    categoryView.CREATED_BY           = category.CREATED_BY;
                    categoryView.CREATED_TIME         = category.CREATED_TIME;
                    categoryView.LAST_MODIFIED_BY     = category.LAST_MODIFIED_BY;
                    categoryView.LAST_MODIFIED_TIME   = category.LAST_MODIFIED_TIME;

                    if (category.TOURIS_TM_SUB_CATEGORY.Count > 0)
                    {
                        foreach (var item in category.TOURIS_TM_SUB_CATEGORY)
                        {
                            TOURIS_TV_SUB_CATEGORY subCategory = new TOURIS_TV_SUB_CATEGORY();
                            subCategory.ID          = item.ID;
                            subCategory.ADDRESS     = item.ADDRESS;
                            subCategory.CATEGORY_ID = item.CATEGORY_ID;
                            subCategory.END_TIME    = item.END_TIME;
                            subCategory.START_TIME  = item.START_TIME;
                            subCategory.SUB_CATEGORY_DESCRIPTION = item.SUB_CATEGORY_DESCRIPTION;
                            subCategory.SUB_CATEGORY_NAME        = item.SUB_CATEGORY_NAME;
                            subCategory.VILLAGE_ID = item.VILLAGE_ID;
                            subCategory.PHOTO_PATH = item.PHOTO_PATH;

                            categoryView.TOURIS_TV_SUB_CATEGORY.Add(subCategory);
                        }
                    }

                    rs.SetSuccessStatus();
                }
                resObj = JObject.FromObject(res.ResGetDataTable(new object[] { categoryView }, null));

                return(Content(HttpStatusCode.OK, resObj));
            }
            catch (Exception ex)
            {
                rs.SetErrorStatus(ex.Message);
                resObj = JObject.FromObject(res.ResGetDataTable(new object[] { rs }, new Exception(eFunc.fg.DataNf)));
                return(Content(HttpStatusCode.BadRequest, resObj));
            }
        }
        public ResultStatus Add(TOURIS_TM_CATEGORY category)
        {
            try
            {
                _ctx.TOURIS_TM_CATEGORY.Add(category);
                _ctx.SaveChanges();
                rs.SetSuccessStatus();
            }
            catch (Exception ex)
            {
                rs.SetErrorStatus(ex.Message);
            }

            return(rs);
        }
Beispiel #3
0
        public IHttpActionResult Add(TOURIS_TV_CATEGORY categoryView)
        {
            ApiResData res = new ApiResData();

            try
            {
                if (!ModelState.IsValid)
                {
                    rs.SetErrorStatus(eFunc.fg.SFailed);
                    resObj = JObject.FromObject(res.ResCUD(new object[] { rs }, eFunc.fg.Save, new Exception(eFunc.fg.DataIsntValid)));
                    return(Content(HttpStatusCode.NotFound, resObj));
                }

                TOURIS_TM_CATEGORY category = new TOURIS_TM_CATEGORY();
                category.CATEGORY_CODE        = categoryView.CATEGORY_CODE;
                category.CATEGORY_NAME        = categoryView.CATEGORY_NAME;
                category.CATEGORY_DESCRIPTION = categoryView.CATEGORY_DESCRIPTION;
                category.URL          = categoryView.URL;
                category.CLASS        = categoryView.CLASS;
                category.PHOTO_PATH   = categoryView.PHOTO_PATH;
                category.CREATED_BY   = categoryView.CREATED_BY;
                category.CREATED_TIME = categoryView.CREATED_TIME;
                category.ROW_STATUS   = eStat.fg.IsActive;

                rs = repo.Add(category);
                if (rs.IsSuccess)
                {
                    rs.SetSuccessStatus();
                }
                else
                {
                    rs.SetErrorStatus(eFunc.fg.SFailed);
                }

                resObj = JObject.FromObject(res.ResCUD(new object[] { rs }, eFunc.fg.Save, null));

                return(Content(HttpStatusCode.OK, resObj));
            }
            catch (Exception ex)
            {
                rs.SetErrorStatus(ex.Message);
                resObj = JObject.FromObject(res.ResCUD(new object[] { rs }, eFunc.fg.Save, new Exception(eFunc.fg.SFailed)));
                return(Content(HttpStatusCode.BadRequest, resObj));
            }
        }
        public ResultStatus Delete(int id, string modifiedBy, DateTime modifiedTime)
        {
            try
            {
                TOURIS_TM_CATEGORY category = _ctx.TOURIS_TM_CATEGORY.Find(id);
                category.LAST_MODIFIED_TIME = modifiedTime;
                category.LAST_MODIFIED_BY   = modifiedBy;
                category.ROW_STATUS         = eStat.fg.NotActive;

                _ctx.Entry(category).State = EntityState.Modified;
                _ctx.SaveChanges();
                rs.SetSuccessStatus();
            }
            catch (Exception ex)
            {
                rs.SetErrorStatus(ex.Message);
            }

            return(rs);
        }
        public ResultStatus Edit(TOURIS_TM_CATEGORY category)
        {
            try
            {
                TOURIS_TM_CATEGORY categoryNew = _ctx.TOURIS_TM_CATEGORY.Find(category.ID);
                categoryNew.CATEGORY_CODE        = category.CATEGORY_CODE;
                categoryNew.CATEGORY_NAME        = category.CATEGORY_NAME;
                categoryNew.CATEGORY_DESCRIPTION = category.CATEGORY_DESCRIPTION;
                categoryNew.URL                = category.URL;
                categoryNew.CLASS              = category.CLASS;
                categoryNew.PHOTO_PATH         = category.PHOTO_PATH;
                categoryNew.LAST_MODIFIED_TIME = category.LAST_MODIFIED_TIME;
                categoryNew.LAST_MODIFIED_BY   = category.LAST_MODIFIED_BY;
                _ctx.Entry(categoryNew).State  = System.Data.Entity.EntityState.Modified;
                _ctx.SaveChanges();
                rs.SetSuccessStatus();
            }
            catch (Exception ex)
            {
                rs.SetErrorStatus(ex.Message);
            }

            return(rs);
        }