public ActionResult Create(CreateStudioViewModel createStudio) { createStudio.name = createStudio.name?.Trim(); createStudio.SelectedCity = createStudio.SelectedCity?.Trim(); createStudio.SelectedState = createStudio.SelectedState?.Trim(); ViewBag.IsStudioSetting = "true"; ViewBag.Header = "Create New Studio"; ViewBag.IsStudioSetting = "1"; if (string.IsNullOrWhiteSpace(createStudio.name)) { ModelState.AddModelError("name", "Studio Name cannot be null"); } else { if (db.Studios.FirstOrDefault(x => x.name.ToLower() == createStudio.name.ToLower()) != null) { ModelState.AddModelError("name", "Studio Name is not available"); } } if (!string.IsNullOrWhiteSpace(createStudio.phoneNum) && !int.TryParse(createStudio.phoneNum, out int result)) { ModelState.AddModelError("phoneNum", "Invalid Phone Number"); } if (!string.IsNullOrWhiteSpace(createStudio.email) && !Backbone.IsValidEmail(createStudio.email)) { ModelState.AddModelError("email", "Invalid Email Address"); } if (ModelState.IsValid) { var studio = new Studio(); studio.name = createStudio.name; studio.shortDesc = createStudio.shortDesc; studio.phoneNum = createStudio.phoneNum; studio.email = createStudio.email; studio.State = createStudio.SelectedState; studio.City = createStudio.SelectedCity; studio.longDesc = createStudio.longDesc; studio.uniquename = (new Backbone()).Random(5); if (!string.IsNullOrWhiteSpace(createStudio.Facebook)) { studio.StudioLinks.Add(new StudioLink { name = "Facebook", address = createStudio.Facebook }); } if (!string.IsNullOrWhiteSpace(createStudio.Twitter)) { studio.StudioLinks.Add(new StudioLink { name = "Twitter", address = createStudio.Twitter }); } if (!string.IsNullOrWhiteSpace(createStudio.Instagram)) { studio.StudioLinks.Add(new StudioLink { name = "Instagram", address = createStudio.Instagram }); } UserStudio userCred = new UserStudio { userid = UserAuthentication.Identity().id, studioroleid = 1 }; studio.UserStudios.Add(userCred); db.Studios.Add(studio); db.SaveChanges(); AzureBlob blob = new AzureBlob(4); try { blob.MoveBlobFromTemp(2, studio.id.ToString(), createStudio.ImgLogo); studio.ImgLogo = createStudio.ImgLogo; } catch { } try { blob.MoveBlobFromTemp(2, studio.id.ToString(), createStudio.ImgCover); studio.ImgCover = createStudio.ImgCover; } catch { } db.SaveChanges(); return(Redirect(string.Format("/{0}", studio.uniquename))); } return(View("~/Views/StudioPermalink/Settings.cshtml", createStudio)); }
public ActionResult Settings(CreateStudioViewModel createStudio) { createStudio.name = createStudio.name?.Trim(); createStudio.SelectedCity = createStudio.SelectedCity?.Trim(); createStudio.SelectedState = createStudio.SelectedState?.Trim(); ViewBag.IsStudioSetting = "1"; ViewBag.Header = "Studio Settings"; if (db.Studios.FirstOrDefault(x => x.name.ToLower() == createStudio.name.ToLower() && x.id != createStudio.id) != null) { ModelState.AddModelError("name", "Studio Name is not available"); } if (!string.IsNullOrWhiteSpace(createStudio.phoneNum) && !int.TryParse(createStudio.phoneNum, out int result)) { ModelState.AddModelError("phoneNum", "Invalid Phone Number"); } if (!string.IsNullOrWhiteSpace(createStudio.email) && !Backbone.IsValidEmail(createStudio.email)) { ModelState.AddModelError("email", "Invalid Email Address"); } if (ModelState.IsValid) { var studio = db.Studios.FirstOrDefault(x => x.id == createStudio.id); AzureBlob blob = new AzureBlob(4); try { blob.MoveBlobFromTemp(2, studio.id.ToString(), createStudio.ImgLogo); studio.ImgLogo = createStudio.ImgLogo; } catch { } try { blob.MoveBlobFromTemp(2, studio.id.ToString(), createStudio.ImgCover); studio.ImgCover = createStudio.ImgCover; } catch { } studio.name = createStudio.name; studio.shortDesc = createStudio.shortDesc; studio.phoneNum = createStudio.phoneNum; studio.email = createStudio.email; studio.State = createStudio.SelectedState; studio.City = createStudio.SelectedCity; studio.longDesc = createStudio.longDesc; if (!string.IsNullOrWhiteSpace(createStudio.Facebook) && studio.StudioLinks.FirstOrDefault(x => x.name.ToLower() == "facebook") == null) { studio.StudioLinks.Add(new StudioLink { name = "Facebook", address = createStudio.Facebook }); } if (!string.IsNullOrWhiteSpace(createStudio.Twitter) && studio.StudioLinks.FirstOrDefault(x => x.name.ToLower() == "twitter") == null) { studio.StudioLinks.Add(new StudioLink { name = "Twitter", address = createStudio.Twitter }); } if (!string.IsNullOrWhiteSpace(createStudio.Instagram) && studio.StudioLinks.FirstOrDefault(x => x.name.ToLower() == "instagram") == null) { studio.StudioLinks.Add(new StudioLink { name = "Instagram", address = createStudio.Instagram }); } for (int i = 0; i < studio.StudioLinks.Count(); i++) { if (studio.StudioLinks.ElementAt(i).name.ToLower() == "facebook") { if (string.IsNullOrWhiteSpace(createStudio.Facebook)) { studio.StudioLinks.Remove(studio.StudioLinks.ElementAt(i)); } else { studio.StudioLinks.ElementAt(i).address = createStudio.Facebook; } } else if (studio.StudioLinks.ElementAt(i).name.ToLower() == "twitter") { if (string.IsNullOrWhiteSpace(createStudio.Twitter)) { studio.StudioLinks.Remove(studio.StudioLinks.ElementAt(i)); } else { studio.StudioLinks.ElementAt(i).address = createStudio.Twitter; } } else if (studio.StudioLinks.ElementAt(i).name.ToLower() == "instagram") { if (string.IsNullOrWhiteSpace(createStudio.Instagram)) { studio.StudioLinks.Remove(studio.StudioLinks.ElementAt(i)); } else { studio.StudioLinks.ElementAt(i).address = createStudio.Instagram; } } } db.SaveChanges(); TempData["Changes"] = "Studio profile have been updated successfully"; return(Redirect(string.Format("/{0}/{1}", ViewBag.StudioUrl, "Settings"))); } return(View(createStudio)); }