public CourseAddViewModel(HandicapStatusViewModel handicapStatus, IList<Navigation.BreadcrumbNavItem> breadcrumb, IEnumerable<SelectListItem> stateListing, CourseAddEnteredData courseAddUserEntered, AntiforgeryTokenSet tokenSet) { HandicapStatus = handicapStatus; CourseAddUserEntered = courseAddUserEntered; Breadcrumb = breadcrumb; StateListing = stateListing; TokenSet = tokenSet; }
public static async Task<int> CourseAdd(ToracGolfContext dbContext, int userId, CourseAddEnteredData CourseData, string courseSavePath) { //course record to add var courseToAdd = new Course { Name = CourseData.CourseName, Description = CourseData.Description, IsActive = true, Pending = true, City = CourseData.City, StateId = Convert.ToInt32(CourseData.StateListing), UserIdThatCreatedCourse = userId, OnlyAllow18Holes = CourseData.OnlyAllow18Holes, CreatedDate = DateTime.Now }; courseToAdd.CourseTeeLocations = CourseData.TeeLocations.Select((x, i) => new CourseTeeLocations { CourseId = courseToAdd.CourseId, Description = x.Description, TeeLocationSortOrderId = i, Front9Par = x.Front9Par.Value, Back9Par = x.Back9Par.Value, Rating = x.Rating.Value, Slope = x.Slope.Value, Yardage = x.Yardage.Value, FairwaysOnCourse = 18 - x.NumberOfPar3s.Value }).ToArray(); //add the course to the context dbContext.Course.Add(courseToAdd); //go save it await dbContext.SaveChangesAsync().ConfigureAwait(false); //do we have a course image? if (CourseData.CourseImage != null) { //grab the byte array for the file var fileToSave = ToracLibrary.Core.Graphics.GraphicsUtilities.ImageFromJsonBase64String(CourseData.CourseImage); //grab where we have the actual .jpg vs png var indexOfSlash = fileToSave.MimeType.IndexOf(@"/"); //grab the file name to save var fileNameToSave = System.IO.Path.Combine(courseSavePath, string.Format("{0}.{1}", courseToAdd.CourseId, fileToSave.MimeType.Substring(indexOfSlash + 1, fileToSave.MimeType.Length - indexOfSlash - 1))); //go save the file System.IO.File.WriteAllBytes(fileNameToSave, fileToSave.FileBytes); } //return the course id return courseToAdd.CourseId; }