예제 #1
0
        public ActionResult EditContact(Guid contactId, Guid?userId)
        {
            Guid token = CheckSessionAuthState(CurrentUser, _authService);

            if (token == Guid.Empty)
            {
                ViewBag.login = true;
                return(View());
            }
            Contact contact = _cryptxService.GetContact(contactId, (userId == null ? Guid.Empty : (Guid)userId), token);

            var model = new ContactCertificatesModel();

            model.ID     = contact.ID;
            model.Name   = contact.Name;
            model.Email  = contact.Email;
            model.Sort   = CertificateSort.FriendlyNameASC;
            model.Filter = CertificateFilter.All;
            //model.Certificates = contact.Certificates;
            foreach (ContactCertificateRelationship contactCertificateRelationship in contact.Certificates)
            {
                var certificate = new ContactCertificate();
                certificate.ContactId    = contact.ID;
                certificate.Id           = contactCertificateRelationship.CertificateID;
                certificate.FriendlyName = contactCertificateRelationship.FriendlyName;
                certificate.Thumbprint   = contactCertificateRelationship.CertificateInfo.Thumbprint;
                certificate.SubjectName  = contactCertificateRelationship.CertificateInfo.SubjectName;
                certificate.IsTest       = contactCertificateRelationship.CertificateInfo.IsTest;

                if (DateTime.Now < contactCertificateRelationship.CertificateInfo.NotBefore)
                {
                    certificate.TimeMessage = "Недействителен до " +
                                              contactCertificateRelationship.CertificateInfo.NotBefore.Date
                                              .ToShortDateString().Replace("/", ".");
                }
                if (DateTime.Now > contactCertificateRelationship.CertificateInfo.NotBefore &&
                    DateTime.Now < contactCertificateRelationship.CertificateInfo.NotAfter)
                {
                    certificate.TimeMessage = "Действителен до " +
                                              contactCertificateRelationship.CertificateInfo.NotAfter.Date
                                              .ToShortDateString().Replace("/", ".");
                }
                else
                {
                    certificate.TimeMessage = "Недействителен с " +
                                              contactCertificateRelationship.CertificateInfo.NotAfter.Date
                                              .ToShortDateString().Replace("/", ".");
                    certificate.TimeMessageStyle = "color: red";
                }
                if (contactCertificateRelationship.CertificateInfo != null &&
                    !string.IsNullOrEmpty(contactCertificateRelationship.CertificateInfo.Organization))
                {
                    certificate.Organization = contactCertificateRelationship.CertificateInfo.Organization;
                }
                if (contactCertificateRelationship.CertificateInfo != null &&
                    !string.IsNullOrEmpty(contactCertificateRelationship.CertificateInfo.INN))
                {
                    certificate.INN = "ИНН " + contactCertificateRelationship.CertificateInfo.INN;
                }

                model.Certificates.Add(certificate);
            }

            var navigation = new MyNavigation();

            if (userId != null && userId != Guid.Empty)
            {
                navigation.Navigations.Add(new NavElement
                {
                    Depth      = 1,
                    Name       = "Администрирование",
                    Action     = "Index",
                    Controller = "Administration",
                    IsUrl      = true
                });
                UserInfoResponse responseUser = _authService.GetUserDataByID((Guid)userId);
                navigation.Navigations.Add(new NavElement
                {
                    Depth = 3,
                    Name  = responseUser.User.Name,
                    IsUrl = false
                });
                navigation.Navigations.Add(new NavElement
                {
                    Depth = 4,
                    Name  = "Контакт: " + contact.Name,
                    IsUrl = false
                });
            }
            else
            {
                navigation.Navigations.Add(new NavElement
                {
                    Depth      = 1,
                    Name       = "Адресная книга",
                    Action     = "Index",
                    Controller = "AddressBook",
                    IsUrl      = true
                });
                navigation.Navigations.Add(new NavElement
                {
                    Depth      = 2,
                    Name       = model.Name,
                    Action     = "",
                    Controller = "",
                    IsUrl      = false
                });
            }
            navigation.Navigations = navigation.Navigations.OrderBy(x => x.Depth).ToList();
            ViewBag.nav            = Helper.HtmlNavElement(navigation, Request.RequestContext);
            ViewBag.UserId         = userId == null ? Guid.Empty : (Guid)userId;
            return(View(model));
        }
예제 #2
0
        public ActionResult EditContact(Guid contactId, ContactCertificatesModel model, string que, string save,
                                        string deleteContact, Guid?userId)
        {
            Guid token = CheckSessionAuthState(CurrentUser, _authService);

            if (token == Guid.Empty)
            {
                ViewBag.login = true;
                return(View());
            }
            if (!string.IsNullOrEmpty(save))
            {
                var contactToEdit = new Contact();
                contactToEdit.ID           = model.ID;
                contactToEdit.Name         = model.Name;
                contactToEdit.Email        = model.Email;
                contactToEdit.Certificates = new List <ContactCertificateRelationship>();
                if (Request.Form.AllKeys.Contains("certificate.FriendlyName"))
                {
                    //List<string> frNames = Request.Form["certificate.FriendlyName"].Split(',').ToList();
                    List <string> ids         = Request.Form["certificate.Id"].Split(',').ToList();
                    List <string> thumbprints = Request.Form["certificate.Thumbprint"].Split(',').ToList();

                    for (int i = 0; i < ids.Count; i++)
                    {
                        var certificateRelationship = new ContactCertificateRelationship();
                        certificateRelationship.CertificateInfo = new CertificateInfo();
                        certificateRelationship.CertificateID   = new Guid(ids[i]);
                        certificateRelationship.CertificateInfo.CertificateId = new Guid(ids[i]);
                        //certificateRelationship.FriendlyName = frNames[i];
                        certificateRelationship.CertificateInfo.Thumbprint = thumbprints[i];
                        contactToEdit.Certificates.Add(certificateRelationship);
                    }
                }
                _cryptxService.EditContact(contactToEdit, (userId == null ? Guid.Empty : (Guid)userId), token);
            }

            List <ContactCertificateRelationship> certificates = _cryptxService.GetContactCertificates(contactId,
                                                                                                       model.SearchString, model.Sort, model.Filter, (userId == null ? Guid.Empty : (Guid)userId), token);

            model.Certificates.Clear();
            Contact contact = _cryptxService.GetContact(contactId, (userId == null ? Guid.Empty : (Guid)userId), token);

            model.Name  = contact.Name;
            model.Email = contact.Email;
            foreach (ContactCertificateRelationship contactCertificateRelationship in certificates)
            {
                var certificate = new ContactCertificate();
                certificate.Id           = contactCertificateRelationship.CertificateID;
                certificate.FriendlyName = contactCertificateRelationship.FriendlyName;
                certificate.Thumbprint   = contactCertificateRelationship.CertificateInfo.Thumbprint;
                certificate.SubjectName  = contactCertificateRelationship.CertificateInfo.SubjectName;
                certificate.IsTest       = contactCertificateRelationship.CertificateInfo.IsTest;

                if (DateTime.Now < contactCertificateRelationship.CertificateInfo.NotBefore)
                {
                    certificate.TimeMessage = "Недействителен до " +
                                              contactCertificateRelationship.CertificateInfo.NotBefore.Date
                                              .ToShortDateString().Replace("/", ".");
                }
                if (DateTime.Now > contactCertificateRelationship.CertificateInfo.NotBefore &&
                    DateTime.Now < contactCertificateRelationship.CertificateInfo.NotAfter)
                {
                    certificate.TimeMessage = "Действителен до " +
                                              contactCertificateRelationship.CertificateInfo.NotAfter.Date
                                              .ToShortDateString().Replace("/", ".");
                }
                else
                {
                    certificate.TimeMessage = "Недействителен с " +
                                              contactCertificateRelationship.CertificateInfo.NotAfter.Date
                                              .ToShortDateString().Replace("/", ".");
                    certificate.TimeMessageStyle = "color: red";
                }
                if (contactCertificateRelationship.CertificateInfo != null &&
                    !string.IsNullOrEmpty(contactCertificateRelationship.CertificateInfo.Organization))
                {
                    certificate.Organization = contactCertificateRelationship.CertificateInfo.Organization;
                }
                if (contactCertificateRelationship.CertificateInfo != null &&
                    !string.IsNullOrEmpty(contactCertificateRelationship.CertificateInfo.INN))
                {
                    certificate.INN = "ИНН " + contactCertificateRelationship.CertificateInfo.INN;
                }
                model.Certificates.Add(certificate);
            }
            //запрос с потерей данных
            if (!string.IsNullOrEmpty(que))
            {
                ViewBag.UserId = userId == null ? Guid.Empty : (Guid)userId;
                return(View(model));
            }
            return(RedirectToAction("ContactList", new { userId = (userId == null ? Guid.Empty : (Guid)userId) }));
        }