Ejemplo n.º 1
0
        /// <summary>Expired Documents view</summary>
        /// <returns>View with expired documents</returns>
        public ActionResult ExpiredDocuments()
        {
            var now = DateTime.Now;
            var treshold = now.AddMonths(2);

            using (var context = new DatabaseContext())
            {
                var expiringDocuments = context.IdentityDocuments
                    .Where(x => x.ExpiryDate != null && x.ExpiryDate >= now && x.ExpiryDate.Value <= treshold)
                    .OrderByDescending(x => x.ExpiryDate)
                    .Include(x => x.Client).ToList();
                var expiredDocuments = context.IdentityDocuments
                    .Where(x => x.ExpiryDate != null && x.ExpiryDate <= now)
                    .OrderByDescending(x => x.ExpiryDate)
                    .Include(x => x.Client).ToList();
                var invalidDocuments = context.IdentityDocuments
                    .Where(x => x.ExpiryDate == null)
                    .Include(x => x.Client).ToList();

                var expiredDocumentsViewModel = new ExpiredDocumentsViewModel
                {
                    ExpiringDocuments = expiringDocuments,
                    ExpiredDocuments = expiredDocuments,
                    InvalidDocuments = invalidDocuments
                };
                return View(expiredDocumentsViewModel);
            }
        }
        public ActionResult Reorder(string button, IdentityDocumentImage identityDocumentImage)
        {
            using (var context = new DatabaseContext())
            {
                var images = context.IdentityDocuments
                    .Where(x => x.Id == identityDocumentImage.IdentityDocumentId)
                    .Include(x => x.IdentityDocumentImages)
                    .First().IdentityDocumentImages;
                var beforeImage = images
                    .Where(x => x.SequenceNumber < identityDocumentImage.SequenceNumber)
                    .OrderByDescending(x => x.SequenceNumber)
                    .FirstOrDefault();
                var currentImage = images
                    .First(x => x.SequenceNumber == identityDocumentImage.SequenceNumber);
                var afterImage = images
                    .Where(x => x.SequenceNumber > identityDocumentImage.SequenceNumber)
                    .OrderBy(x => x.SequenceNumber)
                    .FirstOrDefault();

                var otherImage = (button == "Поднять выше" ? beforeImage : button == "Опустить ниже" ? afterImage : null);
                if (otherImage != null)
                {
                    var swapNumber = otherImage.SequenceNumber;
                    otherImage.SequenceNumber = currentImage.SequenceNumber;
                    currentImage.SequenceNumber = swapNumber;
                    context.SaveChanges();
                }
            }
            return RedirectToAction("WithImages", "IdentityDocument", new { id = identityDocumentImage.IdentityDocumentId });
        }
Ejemplo n.º 3
0
        public ActionResult UnknownArchiveDocuments()
        {
            var doc = new ArchiveDocument();
            var options = doc.TypeOptions().Skip(1).ToList();
            var finder = new TextualApproximationFinder(
                options.Select(x => (ArchiveDocumentType)Enum.Parse(typeof(ArchiveDocumentType), x.Value)).ToList(),
                options.Select(x => x.Text).ToList());

            using (var context = new DatabaseContext())
            {
                var items = context.ArchiveDocuments
                    .Where(x => x.Type == ArchiveDocumentType.Other)
                    .Include(x => x.Client)
                    .ToList()
                    .Select(x => new { ArchiveDocument = x, SuggestedType = finder.FindApproximation(x.Description) })
                    .ToList();

                foreach (var item in items)
                {
                    if (item.SuggestedType == null) continue;
                    item.ArchiveDocument.Type = item.SuggestedType;
                }

                return View(items.Select(x => x.ArchiveDocument).ToList());
            }
        }
Ejemplo n.º 4
0
 /// <summary>Home action - shows the list of clients</summary>
 /// <returns>View with clients</returns>
 public ActionResult Index()
 {
     using (var context = new DatabaseContext())
     {
         var clients = context.Clients
             .Include(x => x.Manager)
             .OrderBy(x => x.NamesLocal).ToList();
         return View(clients);
     }
 }
 /// <summary>Downloads the image from the site</summary>
 /// <param name="id">ID of the image</param>
 /// <returns>Fiew view</returns>
 public FileContentResult Download(int id)
 {
     IdentityDocumentImage identityDocumentImage;
     using (var context = new DatabaseContext())
     {
         identityDocumentImage = context.IdentityDocumentImages.First(x => x.Id == id);
     }
     var storage = new IdentityDocumentImageStorage();
     var bytes = storage.Download(id);
     return File(bytes, "image/" + identityDocumentImage.Format, identityDocumentImage.FileName);
 }
 /// <summary>Downloads the image from the site</summary>
 /// <param name="id">ID of the image</param>
 /// <returns>Fiew view</returns>
 public FileContentResult Download(int id)
 {
     AgreementImage agreementImage;
     using (var context = new DatabaseContext())
     {
         agreementImage = context.AgreementImages.First(x => x.Id == id);
     }
     var storage = new AgreementImageStorage();
     var bytes = storage.Download(id);
     return File(bytes, "image/" + agreementImage.Format, agreementImage.FileName);
 }
Ejemplo n.º 7
0
 /// <summary>GET action of the EDIT functionality</summary>
 /// <returns>View with the object being edited</returns>
 public ActionResult Edit(int id)
 {
     using (var context = new DatabaseContext())
     {
         var contact = context.Contacts
             .Include(x => x.Client.Manager)
             .Include(x => x.Client)
             .First(x => x.Id == id);
         return View(
             new Tuple<Manager, Client, Contact>(contact.Client.Manager, contact.Client, contact));
     }
 }
Ejemplo n.º 8
0
 /// <summary>GET action of the EDIT functionality</summary>
 /// <returns>View with the object being edited</returns>
 public ActionResult Edit(int id)
 {
     using (var context = new DatabaseContext())
     {
         var textMessage = context.TextMessages
             .Include(x => x.Client.Manager)
             .Include(x => x.Client)
             .First(x => x.Id == id);
         return View(
             new Tuple<Manager, Client, TextMessage>(textMessage.Client.Manager, textMessage.Client, textMessage));
     }
 }
 /// <summary>GET action of the EDIT functionality</summary>
 /// <returns>View with the object being edited</returns>
 public ActionResult Edit(int id)
 {
     using (var context = new DatabaseContext())
     {
         var identityDocument = context.IdentityDocuments
             .Include(x => x.Client.Manager)
             .Include(x => x.Client)
             .First(x => x.Id == id);
         return View(
             new Tuple<Manager, Client, IdentityDocument>(
                 identityDocument.Client.Manager, identityDocument.Client, identityDocument));
     }
 }
Ejemplo n.º 10
0
 /// <summary>GET action of the EDIT functionality</summary>
 /// <returns>View with the object being edited</returns>
 public ActionResult Edit(int id)
 {
     using (var context = new DatabaseContext())
     {
         var agreement = context.Agreements
             .Include(x => x.Client.Manager)
             .Include(x => x.Client)
             .First(x => x.Id == id);
         return View(
             new Tuple<Manager, Client, Agreement>(
                 agreement.Client.Manager, agreement.Client, agreement));
     }
 }
Ejemplo n.º 11
0
 public ActionResult SaveFixedUnknownArchiveDocuments(List<ArchiveDocument> archiveDocuments)
 {
     using (var context = new DatabaseContext())
     {
         foreach (var changedItem in archiveDocuments)
         {
             if (changedItem.Type == ArchiveDocumentType.Other) continue;
             var archiveDocument = context.ArchiveDocuments.First(x => x.Id == changedItem.Id);
             archiveDocument.Type = changedItem.Type;
             context.SaveChanges();
         }
         return RedirectToAction("UnknownArchiveDocuments");
     }
 }
 public ActionResult Create(ArchiveDocument archiveDocument)
 {
     using (var context = new DatabaseContext())
     {
         if (!ModelState.IsValid) return View(CreateTuple(context, archiveDocument));
         try
         {
             context.Entry(archiveDocument).State = EntityState.Added;
             context.SaveChanges();
             return RedirectToAction("WithArchiveDocuments", "Client", new { id = archiveDocument.ClientId });
         }
         catch { return View(CreateTuple(context, archiveDocument)); }
     }
 }
Ejemplo n.º 13
0
 public ActionResult Edit(TextMessage textMessage)
 {
     using (var context = new DatabaseContext())
     {
         if (!ModelState.IsValid) return View(CreateTuple(context, textMessage));
         try
         {
             context.Entry(textMessage).State = EntityState.Modified;
             context.SaveChanges();
             return RedirectToAction("WithTextMessages", "Client", new { id = textMessage.ClientId });
         }
         catch { return View(CreateTuple(context, textMessage)); }
     }
 }
Ejemplo n.º 14
0
 /// <summary>GET action of the CREATE functionality</summary>
 /// <returns>View with new object</returns>
 public ActionResult Create(int clientId)
 {
     using (var context = new DatabaseContext())
     {
         var client = context.Clients
             .Include(x => x.Manager)
             .First(x => x.Id == clientId);
         var agreement = new Agreement
         {
             ClientId = clientId
         };
         return View(new Tuple<Manager, Client, Agreement>(client.Manager, client, agreement));
     }
 }
Ejemplo n.º 15
0
        /// <summary>Retrieves data for Client with Archive Documents view</summary>
        /// <param name="id">ID of the client</param>
        /// <returns>View with data</returns>
        public ActionResult WithArchiveDocuments(int id)
        {
            using (var context = new DatabaseContext())
            {
                var client = context.Clients
                    .Where(x => x.Id == id)
                    .Include(x => x.Manager)
                    .Include(x => x.ArchiveDocuments)
                    .First();
                var manager = client.Manager;
                var archiveDocuments = client.ArchiveDocuments
                    .OrderBy(x => x.IssueDate);

                return View(new Tuple<Manager, Client, IEnumerable<ArchiveDocument>>(manager, client, archiveDocuments));
            }
        }
Ejemplo n.º 16
0
 /// <summary>GET action of the CREATE functionality</summary>
 /// <returns>View with new object</returns>
 public ActionResult Create(int clientId)
 {
     using (var context = new DatabaseContext())
     {
         var client = context.Clients
             .Include(x => x.Manager)
             .First(x => x.Id == clientId);
         var textMessage = new TextMessage
         {
             ClientId = clientId,
             DeliveryDate = DateTime.Now,
             DeliveryStatus = DeliveryStatusType.Failure
         };
         return View(new Tuple<Manager, Client, TextMessage>(client.Manager, client, textMessage));
     }
 }
Ejemplo n.º 17
0
        /// <summary>Retrieves data for Client with Text Messages view</summary>
        /// <param name="id">ID of the client</param>
        /// <returns>View with data</returns>
        public ActionResult WithTextMessages(int id)
        {
            using (var context = new DatabaseContext())
            {
                var client = context.Clients
                    .Where(x => x.Id == id)
                    .Include(x => x.Manager)
                    .Include(x => x.TextMessages)
                    .First();
                var manager = client.Manager;
                var textMessages = client.TextMessages
                    .OrderBy(x => x.DeliveryDate);

                return View(new Tuple<Manager, Client, IEnumerable<TextMessage>>(manager, client, textMessages));
            }
        }
Ejemplo n.º 18
0
        /// <summary>Retrieves data for Agreeement with Images view</summary>
        /// <param name="id">ID of the agreement</param>
        /// <returns>View with data</returns>
        public ActionResult WithImages(int id)
        {
            using (var context = new DatabaseContext())
            {
                var agreement = context.Agreements
                    .Include(x => x.Client)
                    .Include(x => x.AgreementImages)
                    .First(x => x.Id == id);
                var images = agreement.AgreementImages
                    .OrderBy(x => x.SequenceNumber)
                    .ToList();

                return View(new Tuple<Manager, Client, Agreement, IEnumerable<AgreementImage>>(
                    agreement.Client.Manager, agreement.Client, agreement, images));
            }
        }
Ejemplo n.º 19
0
        public ActionResult Login(AccountViewModels model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                using (var context = new DatabaseContext())
                {
                    var manager = context.Managers.FirstOrDefault(x => x.LoginName == model.UserName);
                    if (manager != null && manager.Password == model.Password)
                    {
                        FormsAuthentication.SetAuthCookie(manager.Title, model.RememberMe);
                        return RedirectToLocal(returnUrl);
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
        public ActionResult Upload(IdentityDocumentImage identityDocumentImage, HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                using (var context = new DatabaseContext())
                {
                    var identityDocumentImages = context.IdentityDocumentImages
                        .Where(x => x.IdentityDocumentId == identityDocumentImage.IdentityDocumentId).ToList();
                    var sequenceNumber = (byte)(identityDocumentImages.Count == 0 ? 1
                        : identityDocumentImages.Max(x => x.SequenceNumber) + 1);
                    identityDocumentImage.SequenceNumber = sequenceNumber;
                    var bytes = identityDocumentImage.Initialize(file.InputStream, file.ContentLength, file.FileName);

                    context.IdentityDocumentImages.Add(identityDocumentImage);
                    context.SaveChanges();

                    var storage = new IdentityDocumentImageStorage();
                    storage.Upload(identityDocumentImage.Id, bytes);
                }
            }
            return RedirectToAction("WithImages", "IdentityDocument", new { id = identityDocumentImage.IdentityDocumentId });
        }
Ejemplo n.º 21
0
 /// <summary>Creates view model</summary>
 /// <returns>View model</returns>
 private static Tuple<Manager, Client, Contact> CreateTuple(DatabaseContext context, Contact contact)
 {
     contact.Client = context.Clients
         .Include(x => x.Manager)
         .First(x => x.Id == contact.ClientId);
     return new Tuple<Manager, Client, Contact>(contact.Client.Manager, contact.Client, contact);
 }
Ejemplo n.º 22
0
        /// <summary>Adds automatic images to the new agreement</summary>
        private static void AddAutomaticImages(DatabaseContext context, Agreement agreement)
        {
            if (agreement.Type == null) return;

            var fileInfos = new List<Tuple<AgreementType, byte, int>>
            {
                new Tuple<AgreementType, byte, int>(AgreementType.MetricsPassportsIds, 1, 1368708),
                new Tuple<AgreementType, byte, int>(AgreementType.MetricsPassportsIds, 3, 1204257),
                new Tuple<AgreementType, byte, int>(AgreementType.MetricsPassportsIds, 4, 1368708),
                new Tuple<AgreementType, byte, int>(AgreementType.DocumentPackageGathering, 2, 1019502),
                new Tuple<AgreementType, byte, int>(AgreementType.DocumentPackageGathering, 3, 850639)
            };

            var infos = fileInfos.Where(x => x.Item1 == agreement.Type).ToList();
            if (infos.Count == 0) return;

            var storage = new AgreementImageStorage();
            infos.ForEach(info =>
            {
                using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format(
                    "O.Danheli.Azure.WebRole.Content.Agreements.{0}.Page{1}.jpg", info.Item1, info.Item2)))
                {
                    var agreementImage = new AgreementImage
                    {
                        AgreementId = agreement.Id,
                        SequenceNumber = info.Item2
                    };
                    var bytes = agreementImage.Initialize(stream, info.Item3, string.Format("Page{0}.jpg", info.Item2));
                    context.AgreementImages.Add(agreementImage);
                    context.SaveChanges();
                    storage.Upload(agreementImage.Id, bytes);
                }
            });
        }
Ejemplo n.º 23
0
 /// <summary>Creates view model</summary>
 /// <returns>View model</returns>
 private static Tuple<Manager, Client, Agreement> CreateTuple(
     DatabaseContext context, Agreement agreement)
 {
     agreement.Client = context.Clients
         .Include(x => x.Manager)
         .First(x => x.Id == agreement.ClientId);
     return new Tuple<Manager, Client, Agreement>(
         agreement.Client.Manager, agreement.Client, agreement);
 }
Ejemplo n.º 24
0
 /// <summary>Creates view model</summary>
 /// <returns>View model</returns>
 private static Tuple<Manager, Client, TextMessage> CreateTuple(DatabaseContext context, TextMessage textMessage)
 {
     textMessage.Client = context.Clients
         .Include(x => x.Manager)
         .First(x => x.Id == textMessage.ClientId);
     return new Tuple<Manager, Client, TextMessage>(textMessage.Client.Manager, textMessage.Client, textMessage);
 }
 /// <summary>Creates view model</summary>
 /// <returns>View model</returns>
 private static Tuple<Manager, Client, IdentityDocument> CreateTuple(
     DatabaseContext context, IdentityDocument identityDocument)
 {
     identityDocument.Client = context.Clients
         .Include(x => x.Manager)
         .First(x => x.Id == identityDocument.ClientId);
     return new Tuple<Manager, Client, IdentityDocument>(
         identityDocument.Client.Manager, identityDocument.Client, identityDocument);
 }
 public ActionResult Edit(IdentityDocument identityDocument)
 {
     using (var context = new DatabaseContext())
     {
         if (!ModelState.IsValid) return View(CreateTuple(context, identityDocument));
         try
         {
             context.Entry(identityDocument).State = EntityState.Modified;
             context.SaveChanges();
             return RedirectToAction("WithIdentityDocuments", "Client", new { id = identityDocument.ClientId });
         }
         catch { return View(CreateTuple(context, identityDocument)); }
     }
 }
Ejemplo n.º 27
0
 /// <summary>GET action of the CREATE functionality</summary>
 /// <returns>View with new object</returns>
 public ActionResult Create()
 {
     using (var context = new DatabaseContext())
     {
         return View(
             new Tuple<IEnumerable<Manager>, Client>(context.Managers.ToList(), new Client()));
     }
 }
Ejemplo n.º 28
0
        /// <summary>GET action of the EDIT functionality</summary>
        /// <returns>View with the object being edited</returns>
        public ActionResult Edit(int id)
        {
            using (var context = new DatabaseContext())
            {
                var client = context.Clients
                    .First(x => x.Id == id);

                return View(
                    new Tuple<IEnumerable<Manager>, Client>(context.Managers.ToList(), client));
            }
        }
Ejemplo n.º 29
0
 public ActionResult Edit([Bind(Prefix = "Item2")] Client client)
 {
     using (var context = new DatabaseContext())
     {
         if (!ModelState.IsValid) return View(
             new Tuple<IEnumerable<Manager>, Client>(context.Managers.ToList(), client));
         try
         {
             context.Entry(client).State = EntityState.Modified;
             context.SaveChanges();
             return RedirectToAction("WithContacts", new { id = client.Id });
         }
         catch
         {
             return View(
                 new Tuple<IEnumerable<Manager>, Client>(context.Managers.ToList(), client));
         }
     }
 }