Beispiel #1
0
        public ActionResult OnPost(string ActivityName, string Location, int?ExpenseID, string Description, bool Prebook, List <int> ActivityTypes)
        {
            try
            {
                int?       UserGroupID = HttpContext.Session.GetInt32("UserGroupID");
                JsonResult result      = null;
                if (ModelState.IsValid == false)
                {
                    foreach (var modelStateKey in ViewData.ModelState.Keys)
                    {
                        var value = ViewData.ModelState[modelStateKey];
                        foreach (var error in value.Errors)
                        {
                            var errorMessage = error.ErrorMessage;
                            result = new JsonResult(modelStateKey + ": " + errorMessage);
                        }
                    }
                    return(result);
                }
                int ActivityID = _activityData.AddActivity(ActivityName, Location, ExpenseID, Description, Prebook, UserGroupID).Result;

                foreach (var item in ActivityTypes)
                {
                    _activityData.AddActivityxType(ActivityID, Convert.ToInt32(item));
                }

                result = new JsonResult(ActivityID);
                return(result);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw new Exception(ex.ToString());
            }
        }
Beispiel #2
0
        public async Task <IActionResult> OnPost(int ActivityID, string ActivityName, string Location, int ExpenseID, string Description, bool Prebook, List <int> ActivityTypes)
        {
            try
            {
                JsonResult result = null;
                if (ModelState.IsValid == false)
                {
                    foreach (var modelStateKey in ViewData.ModelState.Keys)
                    {
                        var value = ViewData.ModelState[modelStateKey];
                        foreach (var error in value.Errors)
                        {
                            var errorMessage = error.ErrorMessage;
                            result = new JsonResult(modelStateKey + ": " + errorMessage);
                        }
                    }
                    return(result);
                }
                await _activityData.UpdateActivity(ActivityID, ActivityName, Location, ExpenseID, Description, Prebook);

                foreach (var item in ActivityTypes)
                {
                    if (item != 0)
                    {
                        await _activityData.AddActivityxType(ActivityID, Convert.ToInt32(item));
                    }
                }

                result = new JsonResult(ActivityID);
                return(result);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                throw new Exception(ex.ToString());
            }
        }