Esempio n. 1
0
        public async Task <IActionResult> Create([FromBody] Groups inputModel)
        {
            try
            {
                if (string.IsNullOrEmpty(inputModel.Name))
                {
                    throw new Exception($"Name's Group {MessageConst.NOT_EMPTY_INPUT}");
                }
                if (inputModel.Name.Length > 50)
                {
                    throw new Exception($"Name's Group {MessageConst.LENGTH_ERROR}");
                }
                if (Validation.HasSpecialChar(inputModel.Name))
                {
                    throw new Exception($"Name's Group {MessageConst.SPECIAL_CHAR}");
                }
                var exist = await _groupsManager.Find_By_Name(inputModel.Name);

                if (exist != null)
                {
                    throw new Exception($"Name's Group {MessageConst.EXIST}");
                }
                inputModel.CreatedDate = DateTime.Now;
                await _groupsManager.Create(inputModel);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Esempio n. 2
0
        public ActionResult CreateGroup(CreateGroupPageView model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var newGroup = model.NewGroup;

            groupsManager.Create(Mapper.Map <Group, GroupCreateViewModel>(newGroup));

            return(RedirectToRoute("GetGroups"));
        }