public ActionResult LoadGrid(CMS_AccountModels item)
 {
     try
     {
         var  msg     = "";
         bool isCheck = true;
         if (item.Account != null && item.Account.Length > 0 && item.Cookies != null && item.Cookies.Length > 0)
         {
             var temp = ListItem.Where(o => o.Trim() == item.Account.Trim()).FirstOrDefault();
             if (temp == null)
             {
                 var result = _factory.CreateOrUpdate(item, ref msg);
                 if (!result)
                 {
                     isCheck = false;
                 }
             }
             else
             {
                 ViewBag.DuplicateKeyword = "Duplicate account!";
             }
         }
         if (isCheck)
         {
             var model = _factory.GetList();
             return(PartialView("_ListData", model));
         }
         else
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
     }
     catch (Exception e)
     {
         //_logger.Error("Keyword_Search: " + e);
         return(new HttpStatusCodeResult(400, e.Message));
     }
 }
        // GET: Admin/CMSFBAccounts
        public ActionResult Index()
        {
            CMS_AccountModels model = new CMS_AccountModels();

            return(View(model));
        }
Exemplo n.º 3
0
        public bool CreateOrUpdate(CMS_AccountModels model, ref string msg)
        {
            var result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var checkDup = cxt.CMS_Account.Where(o => o.Name == model.Account).FirstOrDefault();

                            if (checkDup == null)
                            {
                                var curSeq = cxt.CMS_Account.OrderByDescending(o => o.Sequence).Select(o => o.Sequence).FirstOrDefault() == null ? 0 : cxt.CMS_Account.OrderByDescending(o => o.Sequence).Select(o => o.Sequence).FirstOrDefault();

                                var dateTimeNow = DateTime.Now;
                                var newAccount  = new CMS_Account()
                                {
                                    Id          = Guid.NewGuid().ToString(),
                                    Name        = model.Account,
                                    Cookies     = model.Cookies,
                                    IsActive    = model.IsActive,
                                    Status      = (byte)Commons.EStatus.Active,
                                    CreatedBy   = model.CreatedBy,
                                    CreatedDate = dateTimeNow,
                                    UpdatedBy   = model.CreatedBy,
                                    UpdatedDate = dateTimeNow,
                                    Sequence    = ++curSeq,
                                };
                                cxt.CMS_Account.Add(newAccount);
                            }
                            else if (checkDup.Status != (byte)Commons.EStatus.Active)
                            {
                                checkDup.Status      = (byte)Commons.EErrorStatus.AccPending;
                                checkDup.UpdatedBy   = model.CreatedBy;
                                checkDup.UpdatedDate = DateTime.Now;
                            }
                            else /* duplicate key word */
                            {
                                msg = "Duplicate account.";
                            }
                            cxt.SaveChanges();
                            trans.Commit();
                        }
                        else
                        {
                            msg = "Unable to edit account.";
                        }
                    }
                    catch (Exception ex)
                    {
                        msg    = "Check connection, please!";
                        result = false;
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }