Пример #1
0
        public ActionResult Add(ViewModel.Newsletter.newsletterItem item)
        {
            if (db.tbl_newsletterUser.Any(a => a.email == item.email))
            {
                return Json(new { isSuccess = "No", msg = lang.mailExist });
            }

            try
            {
                if (ModelState.IsValid)
                {
                    var newItem = new tbl_newsletterUser();
                    newItem.email = item.email;
                    newItem.createTime = DateTime.Now;
                    newItem.ipNo = getUserIP();

                    db.tbl_newsletterUser.Add(newItem);
                    db.SaveChanges();

                    return Json(new { isSuccess = "Ok", msg = lang.newsletterSuccessMsg });

                }
                else
                {
                    string errorMessages = string.Join("<br />", ModelState.Values.Where(E => E.Errors.Count > 0).SelectMany(E => E.Errors).Select(E => E.ErrorMessage).ToArray());
                    return Json(new { isSuccess = "No", msg = errorMessages });
                }
            }
            catch (Exception ex)
            {
                errorSend(ex, "Newsletter Kayıt İşleminde");
                return Json(new { isSuccess = "No", msg = lang.unexpectedErrorMsg });
            }
        }
Пример #2
0
        public ActionResult Dashboard(int pageId, string newsletterChange)
        {
            topCart cartItem = (topCart)ViewData["topCart"];
            userShared us = new userShared(db);

            var userItem = us.getUserById(cartItem.userId);
            var newsletterItem = db.tbl_newsletterUser.Where(a => a.email == userItem.email).FirstOrDefault();

            // Add Newsletter
            if (newsletterItem == null)
            {
                tbl_newsletterUser newsletterNewItem = new tbl_newsletterUser();

                newsletterNewItem.createTime = DateTime.Now;
                newsletterNewItem.email = userItem.email;
                newsletterNewItem.ipNo = getUserIP();

                try
                {
                    db.tbl_newsletterUser.Add(newsletterNewItem);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    errorSend(ex, "Newsletter Add", true);
                }
            }
            else // Remove Newsletter
            {
                try
                {
                    db.tbl_newsletterUser.Remove(newsletterItem);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    errorSend(ex, "Newsletter Remove", true);
                }

            }

            return Dashboard(pageId);
        }