コード例 #1
0
        public ActionResult Edit(int id, CreateErrorMessageViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var product = _mapper.Map <ErrorMessage>(model);

                var isSuccess = _repo.Update(product);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something Went Wrong");
                    return(View(model));
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ModelState.AddModelError("", "Something Went Wrong");
                return(View());
            }
        }
コード例 #2
0
        public ActionResult Create(CreateErrorMessageViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var errorMessge = _mapper.Map <ErrorMessage>(model);
                //   product.ProductId = 2;
                // errorMessge.ErrorMessageId = 1;


                var isSuccess = _repo.Create(errorMessge);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something Went Wrong");
                    return(View(model));
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
コード例 #3
0
        public ActionResult Create(CreateErrorMessageViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                var errorMessge = _mapper.Map <ErrorMessage>(model);


                if (model.ErrorMessageCheckBoxes != null)
                {
                    var emc   = model.ErrorMessageCheckBoxes.Where(q => q.IsChecked == true);
                    int count = 0;
                    foreach (var item in emc)
                    {
                        count++;
                        _repo.CreatErrorTracker(new ErrorMessageTrack()
                        {
                            //  ErrorMessageTrackId = count,
                            ErrorMessageId = item.ErrorMessageId,
                            ProductId      = model.ProductId,
                        });
                    }
                }

                var isSuccess = false;

                if (errorMessge.Message != string.Empty || errorMessge.Message != null)
                {
                    // errorMessge.ErrorMessageId = 100;
                    isSuccess = _repo.Create(errorMessge);
                    var errorMessageId = _repo.FindLatestId();

                    _repo.CreatErrorTracker(new ErrorMessageTrack()
                    {
                        // ErrorMessageTrackId = 111,
                        ErrorMessageId = errorMessageId,
                        ProductId      = model.ProductId,
                    });
                }


                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something Went Wrong");
                    return(View(model));
                }
                // return RedirectToAction(nameof(Index));
                return(RedirectToAction("Create", "ErrorMessage", new { ProductId = model.ProductId }));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
コード例 #4
0
 public ActionResult Delete(int Id, CreateErrorMessageViewModel model)
 {
     try
     {
         // TODO: Add delete logic here
         var errorMessage = _repo.Find(Id);
         if (errorMessage == null)
         {
             return(NotFound());
         }
         var isSuccess = _repo.Delete(errorMessage);
         if (!isSuccess)
         {
             return(View(model));
         }
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View(model));
     }
 }
コード例 #5
0
        // GET: ErrorMessageController/Create
        public ActionResult Create(int ProductId)
        {
            //   ProductId = 2;

            var viewModel    = new CreateErrorMessageViewModel();
            var checkBoxList = new List <ErrorMessageCheckBox>();

            viewModel.ProductId = ProductId;
            var erroViewModel = _repo.GetErrorMessage(viewModel.ProductId);

            foreach (var item in erroViewModel)
            {
                checkBoxList.Add(new ErrorMessageCheckBox()
                {
                    ErrorMessageId = item.ErrorMessageId,
                    IsChecked      = false,
                    Text           = item.Message,
                });
            }

            viewModel.ErrorMessageCheckBoxes = checkBoxList;

            return(View(viewModel));
        }