Example #1
0
 public static AgencyInfo Transform(Agency agency)
 {
     return new AgencyInfo
     {
         Id = agency.Id,
         Name = agency.Name,
         Address = agency.Address,
         Latitude = (double?)agency.Latitude,
         Longitude = (double?)agency.Longitude,
         CSZ = agency.City + ", " + agency.State + " " + agency.ZipCode,
         Phone = agency.Phone,
         Website = agency.Website,
     };
 }
Example #2
0
        public void Save(Agency agency, string username = null, string password = null)
        {
            if (string.IsNullOrWhiteSpace(agency.Name))
            {
                throw new ApplicationException("Please enter an agency name.");
            }
            else
            {
                agency.Name = agency.Name.Trim();
            }

            if (agency.IsNew && _db.Agencies.Any(x => x.Name == agency.Name))
            {
                throw new ApplicationException("The agency name '" + agency.Name + "' already exists. Please enter a unqiue name for the new agency.");
            }

            if (!string.IsNullOrEmpty(username) && !string.IsNullOrWhiteSpace(password))
            {
                var user = _db.Users.SingleOrDefault(x => x.Email == username);
                if (user == null)
                {
                    user = new User {Email = username, Password = password, Active = true};
                }
                else if (user.Password != password)
                {
                    throw new ApplicationException("Invalid password");
                }
                agency.User = user;
            }

            if (!string.IsNullOrWhiteSpace(agency.Website) && !agency.Website.ToLower().StartsWith("http"))
            {
                agency.Website = "http://" + agency.Website;
            }

            _db.Save(agency, agency.IsNew);
            _db.SaveChanges();
        }
Example #3
0
        public void SaveLogo(HttpPostedFileBase file, Agency agency)
        {
            if (file == null || file.ContentLength == 0 || file.InputStream == null || string.IsNullOrWhiteSpace(file.FileName))
                return;

            var ext = Path.GetExtension(file.FileName).ToLower().Trim('.');
            if (!IMAGE_EXTENSIONS.Contains(ext))
                return;

            if (agency.Id == 0)
                return;

            //Delete existing logo
            if (agency.Logo != null)
            {
                try
                {
                    var existingLogoPath = HostingEnvironment.MapPath(agency.Logo);
                    if (existingLogoPath != null && File.Exists(existingLogoPath))
                    {
                        File.Delete(existingLogoPath);
                    }
                }
                catch
                {
                    //ignore errors
                }
            }

            agency.Logo = VirtualPathUtility.ToAbsolute("~/Content/logos/" + agency.Id + "-" + agency.Name.Slug() + "." + ext);

            //Save Logo
            var logoPath = HostingEnvironment.MapPath(agency.Logo);
            Directory.CreateDirectory(Path.GetDirectoryName(logoPath));
            file.SaveAs(logoPath);

            _db.SaveChanges();
        }
Example #4
-1
 private static object GetValue(PropertyInfo prop, Agency agency, IDictionary<string, string> codeDict)
 {
     if (prop.PropertyType == typeof(string[]))
     {
         var arr = (string[])prop.GetValue(agency);
         return string.Join("; ", arr.Select(x => codeDict[x]));
     }
     else
     {
         return prop.GetValue(agency);
     }
 }