コード例 #1
0
        public virtual ActionResult AddOrUpdate(TextDefaultViewModel model)
        {
            try
            {
                Tuple <bool, string> state;
                ModelState.Remove("Id");
                if (!ModelState.IsValid)
                {
                    return(Json(new { isError = true, Msg = "ورودی نا معتبر!" }));
                }

                var text = new TextDefault
                {
                    Id              = model.Id ?? 0,
                    UnivercityId    = Convert.ToInt64(User.LevelId()),
                    Text            = model.Text,
                    TextDefaultType = model.TextDefaultType
                };
                if (model.Id == null || model.Id == 0)
                {
                    state = _textDefaultService.AddOrUpdate(text, StateOperation.درج);
                }
                else
                {
                    state = _textDefaultService.AddOrUpdate(text, StateOperation.ویرایش);
                }

                return(Json(new { isError = false, Msg = state.Item2 }));
            }
            catch (DbEntityValidationException ex)
            {
                return(Json(new { isError = true, Msg = "خطا در ثبت اطلاعات!" }));
            }
        }
コード例 #2
0
 public Tuple <bool, string> AddOrUpdate(TextDefault textDefault, StateOperation stateOperation)
 {
     try
     {
         if (stateOperation == StateOperation.درج)
         {
             _textVoteService.Add(textDefault);
         }
         else
         {
             _textVoteService.Update(textDefault);
         }
         _unitOfWork.SaveChanges();
         return(new Tuple <bool, string>(true, "عملیات ثبت شد"));
     }
     catch (Exception ex)
     {
         return(new Tuple <bool, string>(false, "خطا در انجام عملیات"));
     }
 }