コード例 #1
0
        public ActionResult Create(MapLocation model)
        {
            try
            {
                var mapLocation = new MapLocation
                {
                    Title = model.Title ?? "",
                    TitleEn = model.TitleEn ?? "",
                    LocationLat = model.LocationLat,
                    LocationLng = model.LocationLng,
                    LocationContentAddress = HttpUtility.HtmlDecode(model.LocationContentAddress),
                    LocationContentAddressEn = HttpUtility.HtmlDecode(model.LocationContentAddressEn),
                    LocationContentEmail = model.LocationContentEmail,
                    LocationContentPhone = model.LocationContentPhone,
                    LocationTitle = model.LocationTitle,
                    LocationTitleEn = model.LocationTitleEn,
                    SortOrder = model.SortOrder
                };

                _context.MapLocations.Add(mapLocation);
                _context.SaveChanges();

                return RedirectToAction("Index");
            }

            catch (Exception ex)
            {
                TempData["errorMessage"] = !string.IsNullOrEmpty(ex.GetEntityValidationException())
                    ? ex.GetEntityValidationException()
                    : ex.Message;
                return View(model);
            }
        }
コード例 #2
0
        public ActionResult Edit(int id, MapLocation model)
        {
            var mapLocation = _context.MapLocations.First(a => a.Id == model.Id);
            mapLocation.Title = model.Title ?? "";
            mapLocation.TitleEn = model.TitleEn ?? "";
            mapLocation.LocationLat = model.LocationLat;
            mapLocation.LocationLng = model.LocationLng;
            mapLocation.LocationContentAddress = HttpUtility.HtmlDecode(model.LocationContentAddress);
            mapLocation.LocationContentAddressEn = HttpUtility.HtmlDecode(model.LocationContentAddressEn);
            mapLocation.LocationContentEmail = model.LocationContentEmail;
            mapLocation.LocationContentPhone = model.LocationContentPhone;
            mapLocation.LocationTitle = model.LocationTitle;
            mapLocation.LocationTitleEn = model.LocationTitleEn;
            mapLocation.SortOrder = model.SortOrder;

            _context.SaveChanges();
            return RedirectToAction("Index");
        }