public JsonResult Create(Activity activ, string userName) { UpdateModel(activ); activ.firstID = activ.ID; if (activ.nameID == 0) { if (activ.typeID == def.byKeys(LCategory.activityType, LActType.Assembly)) { activ.nameID = def.byKeys(LCategory.activityName, LActName.Assembly); } else if (activ.typeID == def.byKeys(LCategory.activityType, LActType.OrgMtg)) { activ.nameID = def.byKeys(LCategory.activityName, LActName.OrgMtg); } else { throw new MacheteIntegrityException("Something went wrong with Activity Types."); } } if (activ.dateEnd < activ.dateStart) { return(Json(new { jobSuccess = false, rtnMessage = "End date must be greater than start date." })); } Activity firstAct = serv.Create(activ, userName); var result = map.Map <Activity, ViewModel.Activity>(firstAct); if (activ.recurring) { result.tablabel = "Recurring event with " + firstAct.teacher; result.tabref = "/Activity/CreateMany/" + Convert.ToString(firstAct.ID); } return(Json(new { sNewRef = result.tabref, sNewLabel = result.tablabel, iNewID = result.ID, jobSuccess = true })); }
public async Task <JsonResult> Create(Activity activity, string userName) { if (!await TryUpdateModelAsync(activity, "")) { return(Json(new { jobSuccess = false })); } if (activity.dateEnd < activity.dateStart) { return(Json(new { jobSuccess = false, rtnMessage = "End date must be greater than start date." })); } // leave for now, can be substituted with a reference method var assemblyType = _defaults.byKeys(LCategory.activityType, LActType.Assembly); var assemblyName = _defaults.byKeys(LCategory.activityName, LActName.Assembly); var orgMtgType = _defaults.byKeys(LCategory.activityType, LActType.OrgMtg); var orgMtgName = _defaults.byKeys(LCategory.activityName, LActName.OrgMtg); var activityNameEmpty = activity.nameID == 0; activity.notes = activity.notes ?? ""; if (activity.typeID == assemblyType && activityNameEmpty) { activity.nameID = assemblyName; } if (activity.typeID == orgMtgType && activityNameEmpty) { activity.nameID = orgMtgName; } activity.firstID = activity.ID; // activity.dateStart = TimeZoneInfo.ConvertTimeToUtc(activity.dateStart, _clientTimeZoneInfo); activity.dateEnd = TimeZoneInfo.ConvertTimeToUtc(activity.dateEnd, _clientTimeZoneInfo); activity = _serv.Create(activity, userName); var result = _map.Map <Activity, ViewModel.Activity>(activity); // there are no dates to worry about in this mapping return(Json(new { sNewRef = result.tabref, sNewLabel = result.tablabel, iNewID = result.ID, jobSuccess = true })); }