Exemplo n.º 1
0
        public ActionResult SaveOrEdit(Location location)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    String address = location.Address.ToStr() + " "
                                     + location.City.ToStr() + " "
                                     + location.State.ToStr() + " "
                                     + location.Postal.ToStr() + " "
                                     + location.Country.ToStr() + " ";
                    address       = address.Trim();
                    location.Name = address;
                    if (!String.IsNullOrEmpty(address))
                    {
                        var result = LatitudeAndLongitudeParser.GetLatitudeAndLongitude(address);
                        if (result.Count > 0)
                        {
                            location.Longitude = result[1];
                            location.Latitude  = result[0];
                        }
                    }


                    if (location.Id > 0)
                    {
                        location.UpdatedDate = DateTime.Now;
                        LocationRepository.Edit(location);
                    }
                    else
                    {
                        location.State       = true;
                        location.UpdatedDate = DateTime.Now;
                        location.CreatedDate = DateTime.Now;
                        LocationRepository.Add(location);
                    }

                    LocationRepository.Save();

                    if (IsSuperAdmin)
                    {
                        return(RedirectToAction("Index", new { storeId = location.StoreId }));
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to save changes:" + location);
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            return(View(location));
        }