public ActionResult GetContentItemMetaData(string itemId) { var model = new LessonUpdateViewModel(); var retriever = CategoryRetrieverFactory.GetInstance(_worldId); var categories = retriever.GetCategories(); using (var repository = RepositoryFactory.GetInstance(Session)) { var clipDetails = repository.FindClipDetails(itemId); var currencyRetriver = new CurrencyRetriver(HttpContext, Session, repository); var stringManager = new StringsManager(repository); CurrencyDto defaultCurrency = repository.FindDefaultCurrency(); CurrencyDto targetCurrency = currencyRetriver.GetCurrent(); CurrencyDto sourceCurrency = clipDetails.Currency.ConvertToCurrencyDto() ?? defaultCurrency; var teacherFirstName = clipDetails.GetLocalizedPointerValue("teacher", "firstName"); var teacherLastName = clipDetails.GetLocalizedPointerValue("teacher", "lastName"); var teacherCityOfResidence = clipDetails.GetLocalizedPointerValue("teacher", "cityOfResidence"); var clipStatusName = clipDetails.GetLocalizedPointerValue("status", "status"); var teacherPublishingStatus = (Session.GetLoggedInUser().GetPointerObject<UserAdminData>("adminData")).GetPointerObjectId( "userPublishingStatus"); var showReadingDates = (repository.FindWorlds(_worldId)).Single().ReadingDates; model.ShowReadingDates = showReadingDates; model.PortalNamePart1 = clipDetails.GetLocalizedField("portalNamePart1"); model.PortalNamePart2 = clipDetails.GetLocalizedField("portalNamePart2"); model.CategoryName1 = categories[0].Label; model.CategoryName2 = categories[1].Label; model.CategoryName3 = categories[2].Label; model.CategoryName4 = categories[3].Label; model.Category1Values = categories[0].Values.ToArray(); model.Category2Values = categories[1].Values.ToArray(); model.Category3Values = categories[2].Values.ToArray(); model.Category4Values = categories[3].Values.ToArray(); model.SelectedCategory1Value = clipDetails.Category1 != null ? clipDetails.Category1.ObjectId : ""; model.SelectedCategory2Value = clipDetails.Category2 != null ? clipDetails.Category2.ObjectId : ""; model.SelectedCategory3Value = clipDetails.Category3 != null ? clipDetails.Category3.ObjectId : ""; model.SelectedCategory4Value = clipDetails.Category4 != null ? clipDetails.Category4.ObjectId : ""; model.Created = clipDetails.CreatedAt.HasValue?clipDetails.CreatedAt.Value.ToString("dd/MM/yyyy"):string.Empty; model.Updated = clipDetails.UpdatedAt.HasValue ? clipDetails.UpdatedAt.Value.ToString("dd/MM/yyyy") : string.Empty; model.Version = clipDetails.Version; model.Remarks_he_il = clipDetails.Remarks_he_il; model.Remarks_en_us = clipDetails.Remarks_en_us; model.Performer_he_il = clipDetails.Performer_he_il; model.Performer_en_us = clipDetails.Performer_en_us; model.Description_he_il = clipDetails.Description_he_il; model.Description_en_us = clipDetails.Description_en_us; var lessonPrice = CurrencyConverter.Convert(clipDetails.Price, sourceCurrency, targetCurrency); var lessonPriceWithSupport = CurrencyConverter.Convert(clipDetails.SupportPrice, sourceCurrency, targetCurrency); model.LessonPrice = lessonPrice.ToString("0.00"); model.SupportPrice = lessonPriceWithSupport.ToString("0.00"); model.MinimumPrice = CurrencyConverter.Convert(clipDetails.GetPointerValue<double>("category3", "minPrice"), sourceCurrency, targetCurrency).ToString("0.00"); model.TeacherFirstName = string.IsNullOrEmpty(teacherFirstName) ? string.Empty : teacherFirstName; model.TeacherLastName = string.IsNullOrEmpty(teacherLastName) ? string.Empty : teacherLastName; model.TeacherResidence = teacherCityOfResidence; model.SelectedStatus = clipDetails.Status.ObjectId; model.CalendarRegional = Language.Direction == LanguageDirection.RTL ? "he" : ""; model.IsRTL = Language.Direction == LanguageDirection.RTL; model.CurrencyId = clipDetails.Currency != null ? clipDetails.Currency.ObjectId : string.Empty; model.DefaultCurrencyId = repository.FindDefaultCurrency().ObjectId; model.LessonTitleTemplatePart1 = stringManager.GetTemplate(_worldId, StringTemplates.TitlePart1, Language.CurrentLanguageCode); model.LessonTitleTemplatePart2 = stringManager.GetTemplate(_worldId, StringTemplates.TitlePart2, Language.CurrentLanguageCode); model.StatusValues = repository.FindStatusOptionsByTeacherPublishingStatusAndClipStatus(teacherPublishingStatus, clipDetails.Status.ObjectId, Session.GetLoggedInUserRoleName() == RoleNames.ADMINISTRATORS); if (!model.StatusValues.Any(item => item.Key == clipDetails.Status.ObjectId)) { var statusValuesList = new List<KeyValuePair<string, string>>(model.StatusValues); statusValuesList.Insert(0, new KeyValuePair<string, string>(clipDetails.Status.ObjectId, clipStatusName)); model.StatusValues = statusValuesList.ToArray(); } if (clipDetails.ReadingDates != null) { foreach (var readingDate in clipDetails.ReadingDates) { model.ReadingDates.Add(((DateTime) readingDate).ToString("dd/MM/yyyy")); } } return Json(model, JsonRequestBehavior.AllowGet); } }
private BundleUpdateViewModel GetBundleInitViewModel(Bundle selectedBundle) { var model = new BundleUpdateViewModel(); var retriever = CategoryRetrieverFactory.GetInstance(_worldId); var categories = retriever.GetCategories(); using (var repository = RepositoryFactory.GetInstance(Session)) { var newStatus = repository.FindClipStatuses().Single(x => x.Status == LessonStatus.New); var stringManager = new StringsManager(repository); var status = selectedBundle != null ? selectedBundle.Status.ObjectId : newStatus.ObjectId; var clipStatusName = selectedBundle.GetLocalizedPointerValue("status", "status"); var teacherPublishingStatus = Session.GetLoggedInUser().GetPointerValue<ParseObject>("adminData", "userPublishingStatus").ObjectId; model.CategoryName1 = categories[0].Label; model.CategoryName2 = categories[1].Label; model.CategoryName3 = categories[2].Label; model.CategoryName4 = categories[3].Label; var emptyValue = new CategoryValuesDto { Value_en_us = MyMentorResources.phSelecteCategory, Value_he_il = MyMentorResources.phSelecteCategory, Key = string.Empty }; categories[0].Values.Insert(0, emptyValue); categories[1].Values.Insert(0, emptyValue); categories[2].Values.Insert(0, emptyValue); categories[3].Values.Insert(0, emptyValue); model.Category1Values = categories[0].Values.ToArray(); model.Category2Values = categories[1].Values.ToArray(); model.Category3Values = categories[2].Values.ToArray(); model.Category4Values = categories[3].Values.ToArray(); model.BundleTitleMask = stringManager.GetTemplate(_worldId, StringTemplates.BundleTitlePattern,Language.CurrentLanguageCode); model.LessonsExplanation = stringManager.GetLocalizedString(Strings.BundleLessonExplanation); model.StatusValues =repository.FindStatusOptionsByTeacherPublishingStatusAndClipStatus(teacherPublishingStatus, status,Session.GetLoggedInUserRoleName() == RoleNames.ADMINISTRATORS); if (selectedBundle != null) { if (!model.StatusValues.Any(item => item.Key == selectedBundle.Status.ObjectId)) { var statusValuesList = new List<KeyValuePair<string, string>>(model.StatusValues); statusValuesList.Insert(0, new KeyValuePair<string, string>(selectedBundle.Status.ObjectId, clipStatusName)); model.StatusValues = statusValuesList.ToArray(); } } return model; } }