public static void SaveGroupSettings(Person currentPerson, GroupDto groupSettings)
        {
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                //Check to see if the address already exists

                var address = new Address();

                if (groupSettings.AddressId > 0)
                {
                    address = (from a in context.Addresses
                               where a.AddressId == groupSettings.AddressId
                               select a).FirstOrDefault();

                    if (address == null) //Should never happen, but just to be sure
                    {
                        address = new Address {Created = DateTime.Now};
                        groupSettings.AddressId = 0;
                    }
                }
                else
                {
                    address.Created = DateTime.Now;
                }

                address.Line1 = groupSettings.Address1 ?? string.Empty;
                address.Line2 = groupSettings.Address2 ?? string.Empty;
                address.Line3 = groupSettings.Address3 ?? string.Empty;
                address.Line4 = groupSettings.Address4 ?? string.Empty;
                address.AddressType = groupSettings.AddressType ?? string.Empty;
                address.Lat = groupSettings.Lat;
                address.Long = groupSettings.Lng;
                address.Changed = DateTime.Now;

                if (groupSettings.AddressId == 0)
                {
                    context.Addresses.AddObject(address);
                }

                var group = (from g in context.Groups
                             where g.GroupId == groupSettings.GroupId
                             select g).FirstOrDefault();

                group.Address = address;

                context.SaveChanges();
            }
        }
Example #2
0
        public JsonResult SaveGroupAddress(GroupDto groupSettings)
        {
            bool sessionTimedOut = false;
            if (Session[SessionVariable.LoggedOnPerson] == null)
            {
                sessionTimedOut = true;
            }
            else
            {
                Person currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                //TODO Check for User Roles
                GroupDataAccessor.SaveGroupSettings(currentPerson, groupSettings);
            }

            var response = new
            {
                SessionTimeOut = sessionTimedOut,
                Message = "Address Saved"
            };

            return Json(response, JsonRequestBehavior.AllowGet);
        }