Пример #1
0
        public ActionResult Confirm(int?id)
        {
            ViewBag.Current = "TypeMails";


            TypeMail mail = _context.TypeMails.Find(id);

            _context.TypeMails.Remove(mail);
            _context.SaveChanges();

            string NotificationTime = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss");

            string                 UserId       = User.Identity.GetUserId();
            Notification           notification = null;
            List <ApplicationUser> Users        = _context.Users.Where(a => !a.Id.Equals(UserId)).ToList();

            foreach (ApplicationUser user in Users)
            {
                notification = new Notification()
                {
                    CreatedAt           = NotificationTime,
                    Active              = false,
                    UserId              = user.Id,
                    Message             = "تم حذف نوع من البريد : " + mail.Name,
                    NotificationOwnerId = UserId
                };
                _context.Notifications.Add(notification);
            }
            _context.SaveChanges();



            return(RedirectToAction("Index", new { Id = "DeleteSuccess" }));
        }
Пример #2
0
        public static bool CheckTypeMailEdit(int id)
        {
            TypeMail mail = db.TypeMails.Find(id);

            if (mail.Type != 0)
            {
                return(false);
            }



            return(true);
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "Id,Name,CreatedAt")] TypeMail TypeMail)

        {
            ViewBag.Current = "TypeMails";

            if (_context.TypeMails.Any(a => a.Name.Equals(TypeMail.Name, StringComparison.OrdinalIgnoreCase)))
            {
                return(RedirectToAction("Index", new { Id = "CreateError" }));
            }
            if (ModelState.IsValid)
            {
                string NotificationTime = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss");


                TypeMail.CreatedAt   = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss");
                TypeMail.CreatedById = User.Identity.GetUserId();

                _context.TypeMails.Add(TypeMail);
                _context.SaveChanges();


                string                 UserId       = User.Identity.GetUserId();
                Notification           notification = null;
                List <ApplicationUser> Users        = _context.Users.Where(a => !a.Id.Equals(UserId)).ToList();
                foreach (ApplicationUser user in Users)
                {
                    notification = new Notification()
                    {
                        CreatedAt           = NotificationTime,
                        Active              = false,
                        UserId              = user.Id,
                        Message             = "تم إضافة نوع جديد من البريد : " + TypeMail.Name,
                        NotificationOwnerId = UserId
                    };
                    _context.Notifications.Add(notification);
                }
                _context.SaveChanges();


                return(RedirectToAction("Index", new { Id = "CreateSuccess" }));
            }

            return(RedirectToAction("Index"));
        }
Пример #4
0
        public ActionResult Details(int?id)
        {
            ViewBag.Current = "TypeMails";


            if (id == null)
            {
                return(RedirectToAction("BadRequestError", "ErrorController"));
            }

            TypeMail mail = _context.TypeMails.Include(a => a.CreatedBy).Include(a => a.UpdatedBy).SingleOrDefault(a => a.Id == id);

            if (mail == null)
            {
                return(RedirectToAction("HttpNotFoundError", "ErrorController"));
            }

            return(View(mail));
        }
Пример #5
0
        public ActionResult Delete(int?id)
        {
            ViewBag.Current = "TypeMails";


            if (id == null)
            {
                return(RedirectToAction("BadRequestError", "ErrorController"));
            }

            TypeMail mail = _context.TypeMails.Find(id);

            if (mail == null)
            {
                return(RedirectToAction("HttpNotFoundError", "ErrorController"));
            }

            return(View(mail));
        }
Пример #6
0
        public ActionResult Edit(TypeMail mail, string OldName)

        {
            ViewBag.Current = "TypeMails";

            if (_context.TypeMails.Where(a => a.Id != mail.Id).Any(a => a.Name.Equals(mail.Name, StringComparison.OrdinalIgnoreCase)))
            {
                return(RedirectToAction("Index", new { Id = "EditError" }));
            }

            if (ModelState.IsValid)
            {
                mail.UpdatedAt = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss");
                string NotificationTime = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss");
                mail.UpdatedById           = User.Identity.GetUserId();
                _context.Entry(mail).State = EntityState.Modified;
                _context.SaveChanges();


                string                 UserId       = User.Identity.GetUserId();
                Notification           notification = null;
                List <ApplicationUser> Users        = _context.Users.Where(a => !a.Id.Equals(UserId)).ToList();
                foreach (ApplicationUser user in Users)
                {
                    notification = new Notification()
                    {
                        CreatedAt = NotificationTime,
                        Active    = false,
                        UserId    = user.Id,
                        Message   = "تم تعديل اسم نوع البريد من : " + OldName + " إلى :" + mail.Name
                        ,
                        NotificationOwnerId = UserId
                    };
                    _context.Notifications.Add(notification);
                }
                _context.SaveChanges();

                return(RedirectToAction("Index", new { Id = "EditSuccess" }));
            }

            return(RedirectToAction("Index"));
        }
Пример #7
0
        public static bool CheckTypeMaildelete(int id)
        {
            IEnumerable <Document> documents = db.Documents.Where(a => a.TypeMailId == id);

            if (documents.Count() > 0)
            {
                return(false);
            }

            TypeMail mail = db.TypeMails.Find(id);

            if (mail.Type != 0)
            {
                return(false);
            }



            return(true);
        }