コード例 #1
0
        public ActionResult Change_showroom(int?showroomID, string type, string act, string ctrl, string type_act, string lang)
        {
            ShowroomModels showroomModels = new ShowroomModels();
            CityModels     cityModels     = new CityModels();
            DistrictModels districtModels = new DistrictModels();
            Showroom       objShowroom    = new Showroom();
            var            showroom_view  = new Web.Areas.Admin.ViewModels.Showroom_view();
            StringBuilder  sb             = new StringBuilder();

            if (string.IsNullOrEmpty(type))
            {
                type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.CateNews;
            }

            if (string.IsNullOrEmpty(act))
            {
                act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "change_post";
            }

            if (string.IsNullOrEmpty(ctrl))
            {
                ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "adminPost";
            }

            if (showroomID == null)
            {
                showroomID = RouteData.Values["showroom_id"] != null?Convert.ToInt32(RouteData.Values["ShowroomID"].ToString()) : 0;
            }

            if (string.IsNullOrEmpty(lang))
            {
                lang = LanguageModels.ActiveLanguage().LangCultureName;
            }

            if (string.IsNullOrEmpty(type_act))
            {
                type_act = Request.QueryString["type_act"] != null ? Request.QueryString["type_act"].ToString() : CommonGlobal.Add;
                if (showroomID == 0)
                {
                    type_act = CommonGlobal.Add;
                }
                else
                {
                    type_act = CommonGlobal.Edit;
                }
            }

            if (type_act == CommonGlobal.Edit)
            {
                objShowroom = showroomModels.GetShowroomById((int)showroomID);
                showroom_view.ShowroomID = objShowroom.ShowroomID;
                showroom_view.DistrictID = objShowroom.DistrictID;
                showroom_view.Longitude  = objShowroom.Longitude;
                showroom_view.Latitude   = objShowroom.Latitude;
                showroom_view.Name       = objShowroom.Name;
                showroom_view.Address    = objShowroom.Address;
                showroom_view.Phone      = objShowroom.Phone;
                showroom_view.Image      = objShowroom.Image;

                ////Link tab
                sb.Append("<li><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_showroom", ctrl = "adminShowroom", page = "1" }) + "\"><span><span>Danh sách Showroom</span></span></a></li>");
                sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Cập nhật</span></span></a></li>");

                District objDistrict = districtModels.GetDistrictByID(objShowroom.DistrictID);
                ////City and District
                showroom_view.List_city     = cityModels.List_city(objDistrict.CityID);
                showroom_view.List_district = districtModels.List_district(objDistrict.CityID, objShowroom.DistrictID);

                showroom_view.City     = objDistrict.CityID;
                showroom_view.District = objDistrict.DistrictID;
            }
            else
            {
                ////Link tab
                sb.Append("<li><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_showroom", ctrl = "adminShowroom", page = "1", lang = lang }) + "\"><span><span>Danh sách Showroom</span></span></a></li>");
                sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm mới</span></span></a></li>");

                ////City and District
                showroom_view.List_city     = cityModels.List_city(0);
                showroom_view.List_district = districtModels.List_district(0, 0);
            }

            showroom_view.Type          = type;
            showroom_view.Type_act      = type_act;
            showroom_view.Html_link_tab = sb.ToString();
            ////action
            showroom_view.Act               = act;
            showroom_view.Ctrl              = ctrl;
            showroom_view.Parent_action     = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString();
            showroom_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString();
            ////end action

            return(this.PartialView("../control/change_showroom", showroom_view));
        }
コード例 #2
0
        public ActionResult Change_showroom(FormCollection collection, HttpPostedFileBase file_image)
        {
            ShowroomModels showroomModels = new ShowroomModels();
            CityModels     cityModels     = new CityModels();
            DistrictModels districtModels = new DistrictModels();
            Showroom       objShowroom    = new Showroom();
            StringBuilder  sb             = new StringBuilder();
            int            rt             = 0;
            bool           is_valid       = true;
            var            showroom_view  = new Web.Areas.Admin.ViewModels.Showroom_view();

            this.TryUpdateModel(showroom_view);

            if (showroom_view.ShowroomID > 0)
            {
                objShowroom = showroomModels.GetShowroomById(showroom_view.ShowroomID);
            }

            ////validation server
            if (string.IsNullOrEmpty(showroom_view.Name))
            {
                is_valid = false;
                showroom_view.Message = "Bạn cần nhập tên Showroom";
            }

            ////validation server
            if (showroom_view.District == 0)
            {
                is_valid = false;
                showroom_view.Message = "Bạn cần lựa chọn Quận/Huyện";
            }

            ////action
            ////post_view.act = "change_post";
            ////post_view.ctrl = "adminPost";
            showroom_view.Parent_action     = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString();
            showroom_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString();

            if (!is_valid)
            {
                return(this.PartialView("../control/change_showroom", showroom_view));
            }

            ////Post info
            objShowroom.DistrictID = showroom_view.District;
            objShowroom.Name       = showroom_view.Name;
            objShowroom.Address    = showroom_view.Address;
            objShowroom.Phone      = showroom_view.Phone;
            objShowroom.Latitude   = showroom_view.Latitude;
            objShowroom.Longitude  = showroom_view.Longitude;

            var imgPathTemp = "images/newspost/" +
                              DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/";
            var name_time = DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + DateTime.Now.Hour + DateTime.Now.Minute + string.Empty;

            if (file_image != null && file_image.ContentLength > 0 && CommonGlobal.IsImage(file_image) == true)
            {
                string image_small = imgPathTemp + "sc_small_" + name_time + "_" + CommonGlobal.CompleteNamefileImages(file_image.FileName);
                string image_lager = imgPathTemp + "sc_full_" + name_time + "_" + CommonGlobal.CompleteNamefileImages(file_image.FileName);

                ////save image and delete old file
                this.Savephoto(objShowroom.Image, file_image, imgPathTemp, image_small, image_lager);

                ////set image thumb to link catalog
                objShowroom.Image = "/" + image_small;
            }
            else if (string.IsNullOrEmpty(objShowroom.Image))
            {
                objShowroom.Image = "0";
            }
            else
            {
                objShowroom.Image = objShowroom.Image;
            }

            if (showroom_view.ShowroomID != 0 && showroom_view.Type_act == CommonGlobal.Edit)
            {
                rt = showroomModels.Edit(objShowroom);
            }
            else
            {
                objShowroom.CreateDate = DateTime.Now;
                rt = showroomModels.Add(objShowroom);
            }

            if (showroom_view.ShowroomID != 0 && showroom_view.Type_act == CommonGlobal.Edit)
            {
                ////Link tab
                sb.Append("<li><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_showroom", ctrl = "adminShowroom", type = showroom_view.Type, page = "1" }) + "\"><span><span>Danh sách Showroom</span></span></a></li>");
                sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Cập nhật</span></span></a></li>");

                ////list parent
                District objDistrict = districtModels.GetDistrictByID(showroom_view.District);
                ////City and District
                showroom_view.List_city     = cityModels.List_city(objDistrict.CityID);
                showroom_view.List_district = districtModels.List_district(objDistrict.CityID, showroom_view.District);
            }
            else
            {
                ////Link tab
                sb.Append("<li><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_showroom", ctrl = "adminShowroom", type = showroom_view.Type, page = "1" }) + "\"><span><span>Danh sách Showroom</span></span></a></li>");
                sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm mới</span></span></a></li>");

                ////City and District
                showroom_view.List_city     = cityModels.List_city(showroom_view.City);
                showroom_view.List_district = districtModels.List_district(showroom_view.City, showroom_view.District);
            }

            showroom_view.Html_link_tab = sb.ToString();

            if (rt > 0)
            {
                showroom_view.Message    = "Cập nhật thành công!";
                showroom_view.ShowroomID = rt;
                showroom_view.Type_act   = CommonGlobal.Edit;
            }
            else
            {
                showroom_view.Message = "Cập nhật không thành công!";
            }

            return(this.PartialView("../control/change_showroom", showroom_view));
        }