Ejemplo n.º 1
0
        public async Task <IActionResult> CreateNewGroup(string groupName)
        {
            try
            {
                await _groupsService.AddGroupAsync(User.Identity.Name, groupName);
            }
            catch (ApplicationException exception)
            {
                return(Error.FromController(this).ErrorJson("Error!", exception.Message, HttpStatusCode.BadRequest));
            }
            catch
            {
                return(Error.FromController(this).ErrorJson(
                           "Error!",
                           "An unexpected error has occured while processing your request.",
                           HttpStatusCode.InternalServerError));
            }

            return(Ok(
                       new
            {
                title = "Group added.",
                message = "Refresh this page to see changes."
            }));
        }
        private async void OnSave()
        {
            var editingGroup = Mapper.Map <EditableGroup, Group>(Group);

            try
            {
                if (EditMode)
                {
                    await _groupsService.UpdateGroupAsync(editingGroup);
                }
                else
                {
                    await _groupsService.AddGroupAsync(editingGroup);
                }
                Done?.Invoke();
            }
            catch (Exception ex)
            {
                Failed(ex);
            }
            finally
            {
                Group = null;
            }
        }