Esempio n. 1
0
        // GET: /DataCenter/Contacts/Create
        public ActionResult Create()
        {
            //پر کردن دراپ دون لیستها
            IEnumerable <DomainClasses.Models.PseezEnt.Common.ContactList> ContactLists;

            if (User.IsInRole("Admin") || User.IsInRole("ContactListAdmin"))
            {
                ContactLists = _contactListService.GetAll();
            }
            else
            {
                var userId           = _identityUserService.FindUserIdByName(User.Identity.Name);
                var userContactLists =
                    _userContactListService.GetAll(r => r.UserId == userId).Select(r => r.ContactListId);
                ContactLists = _contactListService.GetAll(r => userContactLists.Contains(r.Id));
            }
            ViewBag.ContactListNames = new SelectList(ContactLists, "Name", "Name");

            if (ContactLists.Count() != 0)
            {
                var    firstContactListId      = ContactLists.FirstOrDefault().Id;
                string ContactGroupNamesSelect = null;
                //ContactGroupNamesSelect = null;
                foreach (
                    var contactGroupName in
                    _contactGroupService.GetAll(r => r.ContactListId == firstContactListId).Select(r => r.Name))
                {
                    ContactGroupNamesSelect += "<option value=\"" + contactGroupName + "\">" + contactGroupName +
                                               "</option>";
                }
                ViewBag.ContactGroupNames = ContactGroupNamesSelect;
            }
            return(PartialView("_Create"));
        }
Esempio n. 2
0
        public ActionResult Create(
            [Bind(Include = "Name,Tell,Comment,ContactGroupName,ContactListName")] ContactViewModel contactViewModel)
        {
            if (ModelState.IsValid)
            {
                var a = contactViewModel.MapViewModelToModel();
                a.ContactListId = _contactListService.Find(r => r.Name == contactViewModel.ContactListName).Id;
                if (contactViewModel.ContactGroupName != null)
                {
                    a.ContactGroupId = _contactGroupService.Find(r => r.Name == contactViewModel.ContactGroupName).Id;
                }
                _contactService.Add(a);
                _uow.SaveChanges();
                return(Json(new { success = true }));
            }
            //ViewBag.ContactGroupNames = new SelectList(_contactGroupService.GetAll(), "Name", "Name");
            //ViewBag.ContactListNames = new SelectList(_contactListService.GetAll(), "Name", "Name");
            //پر کردن دراپ دون لیستها
            IEnumerable <DomainClasses.Models.PseezEnt.Common.ContactList> ContactLists;

            if (User.IsInRole("Admin") || User.IsInRole("ContactListAdmin"))
            {
                ContactLists = _contactListService.GetAll();
            }
            else
            {
                var userId           = _identityUserService.FindUserIdByName(User.Identity.Name);
                var userContactLists =
                    _userContactListService.GetAll(r => r.UserId == userId).Select(r => r.ContactListId);
                ContactLists = _contactListService.GetAll(r => userContactLists.Contains(r.Id));
            }
            ViewBag.ContactListNames = new SelectList(ContactLists, "Name", "Name", contactViewModel.ContactListName);

            if (ContactLists.Count() != 0)
            {
                var    firstContactListId      = ContactLists.FirstOrDefault().Id;
                string ContactGroupNamesSelect = null;
                //ContactGroupNamesSelect = null;
                foreach (
                    var contactGroupName in
                    _contactGroupService.GetAll(r => r.ContactListId == firstContactListId).Select(r => r.Name))
                {
                    if (contactGroupName == contactViewModel.ContactGroupName)
                    {
                        ContactGroupNamesSelect += "<option value=" + contactGroupName + " selected>" + contactGroupName +
                                                   "</option>";
                    }
                    else
                    {
                        ContactGroupNamesSelect += "<option value=" + contactGroupName + ">" + contactGroupName +
                                                   "</option>";
                    }
                }
                ViewBag.ContactGroupNames = ContactGroupNamesSelect;
            }
            return(PartialView("_Create", contactViewModel));
        }