public async Task <IActionResult> Create_Or_Update(Menus inputModel)
        {
            try
            {
                if (string.IsNullOrEmpty(inputModel.Name))
                {
                    throw new Exception($"Tên {MessageConst.NOT_EMPTY_INPUT}");
                }
                if (inputModel.Id == 0)
                {
                    inputModel.CreatedDate = DateTime.Now;
                    await _menuManager.Create(inputModel);

                    return(Json(new { Result = true, Message = "Thêm mới dữ liệu thành công" }));
                }
                else
                {
                    inputModel.UpdatedDate = DateTime.Now;
                    await _menuManager.Update(inputModel);

                    return(Json(new { Result = true, Message = "Cập nhật dữ liệu thành công" }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Result = false, Message = ex.Message }));
            }
        }
Beispiel #2
0
        public ActionResult Create(MenuPostViewModel menuPostViewModel)
        {
            if (ModelState.IsValid)
            {
                var menuCreateModel = _mapper.Map <MenuCreateModel>(menuPostViewModel);
                var menuId          = _menuManager.Create(menuCreateModel);

                if (menuPostViewModel.DayId.Length != menuPostViewModel.RecipeId.Length)
                {
                    return(new HttpStatusCodeResult(400));
                }

                return(RedirectToAction("Details/" + menuId));
            }
            return(View(menuPostViewModel));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([FromBody] Menus inputModel)
        {
            try
            {
                var exist = await _menuManager.Find_By_Name(inputModel.Name);

                if (exist != null)
                {
                    throw new Exception($"Tên Menu {MessageConst.EXIST}");
                }

                inputModel.CreatedDate = DateTime.Now;

                await _menuManager.Create(inputModel);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }