Exemplo n.º 1
0
        public ActionResult DeleteDistrict(long DISTRICT_ID = 0)
        {
            if (Request.IsAjaxRequest())
            {
                if (ModelState.IsValid && DISTRICT_ID > 0)
                {
                    using (var service = new ManageDistrictService())
                    {
                        var deleteResult = service.DeleteDistrict(DISTRICT_ID);

                        JsonResult result = Json(new
                        {
                            statusCode = deleteResult ? Constant.SUCCESSFUL : Constant.INTERNAL_SERVER_ERROR
                        }, JsonRequestBehavior.AllowGet);

                        return(result);
                    }
                }
                else
                {
                    var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();
                }
            }

            return(new EmptyResult());
        }
Exemplo n.º 2
0
        /// <summary>
        /// DELETE Town in Area
        /// </summary>
        /// <param name="cityCd"></param>
        /// <param name="districtCd"></param>
        /// <param name="townCD"></param>
        /// <param name="forUser"></param>
        /// <returns></returns>
        public ActionResult DeleteTownInArea(long cityCd = 0, long districtCd = 0, long townCD = 0, int forUser = 0)
        {
            if (Request.IsAjaxRequest())
            {
                if (ModelState.IsValid && cityCd > 0 && districtCd > 0 && townCD > 0)
                {
                    using (var service = new ManageDistrictService())
                    {
                        var deleteResult = service.DeleteTownInArea(cityCd, districtCd, townCD, forUser);

                        JsonResult result = Json(new
                        {
                            statusCode = deleteResult ? Constant.SUCCESSFUL : Constant.INTERNAL_SERVER_ERROR
                        }, JsonRequestBehavior.AllowGet);

                        return(result);
                    }
                }
                else
                {
                    var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();
                }
            }

            return(new EmptyResult());
        }
Exemplo n.º 3
0
        public ActionResult Edit(CityModel model)
        {
            try
            {
                using (ManageDistrictService service = new ManageDistrictService())
                {
                    if (ModelState.IsValid)
                    {
                        bool    isNew  = false;
                        TblCity entity = new TblCity();

                        if (model.ID == 0)
                        {
                            isNew         = true;
                            model.CITY_ID = 1;
                            model.Level   = Constant.CityLevel.District;

                            service.InsertCity(model);
                            JsonResult result = Json(new { isNew = isNew }, JsonRequestBehavior.AllowGet);
                            return(result);
                        }
                        else
                        {
                            isNew         = false;
                            model.CITY_ID = 1;
                            model.Level   = Constant.CityLevel.District;

                            service.UpdateCity(model);
                            JsonResult result = Json(new { isNew = isNew }, JsonRequestBehavior.AllowGet);
                            return(result);
                        }
                    }
                    else
                    {
                        var ErrorMessages = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();
                    }

                    return(new EmptyResult());
                }
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
                System.Web.HttpContext.Current.Session["ERROR"] = ex;
                return(new EmptyResult());
            }
        }
Exemplo n.º 4
0
        public ActionResult GroupList(DataTableModel dt, GroupAreaModel condition)
        {
            if (ModelState.IsValid)
            {
                using (ManageDistrictService service = new ManageDistrictService())
                {
                    int total_row = 0;
                    //condition = Session["SearchGroupAreaList"] as GroupAreaModel ?? new GroupAreaModel();
                    var dataList = service.SearchGroupAreatList(dt, condition, out total_row);

                    int order         = 1;
                    int totalRowCount = dataList.Count();
                    int lastItem      = dt.iDisplayLength + dt.iDisplayStart;

                    var result = Json(
                        new
                    {
                        sEcho                = dt.sEcho,
                        iTotalRecords        = total_row,
                        iTotalDisplayRecords = total_row,
                        aaData               = (from i in dataList
                                                select new object[]
                        {
                            i.GROUP_CD,
                            order++,
                            i.GROUP_NAME != null ? HttpUtility.HtmlEncode(i.GROUP_NAME) : String.Empty,
                            i.FOR_USER_TEXT = GroupForUser.Items[i.FOR_USER].ToString(),
                            i.INS_DATE != null ? i.INS_DATE.Value.ToString("dd/MM/yyyy") : String.Empty,
                            i.UPD_DATE != null ? i.UPD_DATE.Value.ToString("dd/MM/yyyy") : String.Empty,
                            i.DEL_FLG,
                            i.FOR_USER
                        })
                    });
                    SaveRestoreData(condition);
                    result.MaxJsonLength = Int32.MaxValue;
                    return(result);
                }
            }
            return(new EmptyResult());
        }
Exemplo n.º 5
0
        public ActionResult List(DataTableModel dt, DistrictModel condition)
        {
            if (ModelState.IsValid)
            {
                using (ManageDistrictService service = new ManageDistrictService())
                {
                    int total_row = 0;
                    var dataList  = service.SearchDistrictList(dt, condition, out total_row);

                    int order         = 1;
                    int totalRowCount = dataList.Count();
                    int lastItem      = dt.iDisplayLength + dt.iDisplayStart;

                    var result = Json(
                        new
                    {
                        sEcho                = dt.sEcho,
                        iTotalRecords        = total_row,
                        iTotalDisplayRecords = total_row,
                        aaData               = (from i in dataList
                                                select new object[]
                        {
                            i.CITY_CD,
                            order++,
                            i.CITY_NAME != null ? HttpUtility.HtmlEncode(i.CITY_NAME) : String.Empty,
                            i.DISTRICT_CD,
                            i.DISTRICT_NAME != null ? HttpUtility.HtmlEncode(i.DISTRICT_NAME) : String.Empty,
                            i.STATUS == "1"? "Hiển thị" : "Ẩn",
                            i.DEL_FLG
                        })
                    });

                    result.MaxJsonLength = Int32.MaxValue;
                    return(result);
                }
            }
            return(new EmptyResult());
        }
Exemplo n.º 6
0
        public ActionResult EditGroup(GroupAreaModel model)
        {
            try
            {
                using (ManageDistrictService service = new ManageDistrictService())
                {
                    if (ModelState.IsValid)
                    {
                        bool        isNew   = false;
                        bool        success = true;
                        MstDistrict entity  = new MstDistrict();

                        if (model.GROUP_CD == 0)
                        {
                            isNew = true;

                            var groupCd = service.InsertGroupArea(model);
                            if (groupCd > 0)
                            {
                                model.GROUP_CD = groupCd;
                                foreach (var town in model.LIST_TOWN)
                                {
                                    town.GROUP_CD = groupCd;
                                    var updateTown = service.UpdateTownInArea(town, model.FOR_USER);
                                    success = updateTown > 0 ? true : false;
                                    if (!success)
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                success = false;
                            }
                            JsonResult result = Json(new { isNew = isNew, success = success }, JsonRequestBehavior.AllowGet);
                            return(result);
                        }
                        else
                        {
                            isNew = false;

                            var update = service.UpdateGroupArea(model);
                            if (update > 0)
                            {
                                foreach (var town in model.LIST_TOWN)
                                {
                                    town.GROUP_CD = model.GROUP_CD;
                                    var updateTown = service.UpdateTownInArea(town, model.FOR_USER);
                                    success = updateTown > 0 ? true : false;
                                    if (!success)
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                success = false;
                            }

                            JsonResult result = Json(new { isNew = isNew, success = success }, JsonRequestBehavior.AllowGet);
                            return(result);
                        }
                    }
                    else
                    {
                        var ErrorMessages = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();
                    }

                    return(new EmptyResult());
                }
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
                System.Web.HttpContext.Current.Session["ERROR"] = ex;
                return(new EmptyResult());
            }
        }