Agribusiness.Web.Controllers.SeminarApplicationController.GetApplicationPhoto C# (CSharp) Method

GetApplicationPhoto() public method

Gets photo from an application
public GetApplicationPhoto ( int id ) : System.Web.Mvc.FileResult
id int Application Id
return System.Web.Mvc.FileResult
        public FileResult GetApplicationPhoto(int id)
        {
            var application = _applicationRepository.GetNullableById(id);

            byte[] photo = null;
            var contentType = "image/jpeg";

            // application exists
            if (application != null)
            {
                // application does not have a photo
                if (application.Photo == null)
                {
                    var person = application.User.Person;

                    // attempt to assign person's existing main profile picture
                    if (person != null)
                    {
                        photo = person.MainProfilePicture;
                        contentType = string.IsNullOrWhiteSpace(person.ContentType) ? contentType : person.ContentType;
                    }
                }
                else
                {
                    photo = _pictureService.MakeMainProfile(application.Photo);
                    contentType = string.IsNullOrWhiteSpace(application.ContentType) ? contentType : application.ContentType;
                }
            }

            // no photo anywhere, give the placeholder
            if (photo == null)
            {
                // load the default image
                var fs = new FileStream(Server.MapPath("~/Images/profilepicplaceholder.png"), FileMode.Open, FileAccess.Read);
                var img = new byte[fs.Length];
                fs.Read(img, 0, img.Length);
                fs.Close();

                return File(img, "image/jpeg");
            }

            return File(photo, contentType);
        }