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()); } }
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)); } } }
/// <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 archiveDocument = new ArchiveDocument { ClientId = clientId }; return View(new Tuple<Manager, Client, ArchiveDocument>(client.Manager, client, archiveDocument)); } }
/// <summary>Creates view model</summary> /// <returns>View model</returns> private static Tuple<Manager, Client, ArchiveDocument> CreateTuple( DatabaseContext context, ArchiveDocument archiveDocument) { archiveDocument.Client = context.Clients .Include(x => x.Manager) .First(x => x.Id == archiveDocument.ClientId); return new Tuple<Manager, Client, ArchiveDocument>( archiveDocument.Client.Manager, archiveDocument.Client, archiveDocument); }
/// <summary>Creates POC object from its properties</summary> /// <returns>POC object</returns> private static ArchiveDocument ParseEntity(string id, string clientId, string country, string type, string serie, string number, string issueDate, string description) { var archiveDocument = new ArchiveDocument(); int no; if (!int.TryParse(id, out no)) throw new Exception("Incorrect ID during instantiating of Archive Document"); archiveDocument.Id = no; int clientNo; if (!int.TryParse(clientId, out clientNo)) throw new Exception("Incorrect Client ID during instantiating of Archive Document with ID = " + archiveDocument.Id); archiveDocument.ClientId = clientNo; int countryInstance; if (!int.TryParse(country, out countryInstance)) throw new Exception("Incorrect Country during instantiating of Archive Document with ID = " + archiveDocument.Id); switch (countryInstance) { case 1: archiveDocument.Country = ArchiveDocumentCountry.Russia; break; case 2: archiveDocument.Country = ArchiveDocumentCountry.Estonia; break; case 3: archiveDocument.Country = ArchiveDocumentCountry.Latvia; break; case 4: archiveDocument.Country = ArchiveDocumentCountry.Lithuania; break; case 5: archiveDocument.Country = ArchiveDocumentCountry.Finland; break; case 6: archiveDocument.Country = ArchiveDocumentCountry.Usa; break; case 7: archiveDocument.Country = ArchiveDocumentCountry.Ukraine; break; case 8: archiveDocument.Country = ArchiveDocumentCountry.Belarus; break; case 9: archiveDocument.Country = ArchiveDocumentCountry.Moldova; break; case 10: archiveDocument.Country = ArchiveDocumentCountry.Kazakhstan; break; case 200: archiveDocument.Country = ArchiveDocumentCountry.Ussr; break; case 201: archiveDocument.Country = ArchiveDocumentCountry.UssrRussia; break; case 202: archiveDocument.Country = ArchiveDocumentCountry.UssrEstonia; break; case 203: archiveDocument.Country = ArchiveDocumentCountry.UssrLatvia; break; case 204: archiveDocument.Country = ArchiveDocumentCountry.UssrKazakhstan; break; default: if (countryInstance != 0) throw new Exception("Incorrect Country during instantiating of Archive Document with ID = " + archiveDocument.Id); break; } int typeInstance; if (!int.TryParse(type, out typeInstance)) throw new Exception("Incorrect Type during instantiating of Archive Document with ID = " + archiveDocument.Id); switch (typeInstance) { case 5: archiveDocument.Type = ArchiveDocumentType.BirthCertificate; break; case 9: archiveDocument.Type = ArchiveDocumentType.DeathCertificate; break; case 13: archiveDocument.Type = ArchiveDocumentType.MarriageCertificate; break; case 19: archiveDocument.Type = ArchiveDocumentType.NameChangeCertificate; break; case 20: archiveDocument.Type = ArchiveDocumentType.AnnulmentCertificate; break; case 21: archiveDocument.Type = ArchiveDocumentType.EvidenceOfPaternity; break; case 22: archiveDocument.Type = ArchiveDocumentType.MarriageReference; break; case 23: archiveDocument.Type = ArchiveDocumentType.AnnulmentReference; break; case 24: archiveDocument.Type = ArchiveDocumentType.ActOfBirth; break; case 25: archiveDocument.Type = ArchiveDocumentType.ActOfDeath; break; case 26: archiveDocument.Type = ArchiveDocumentType.BaptismalCertificate; break; case 27: archiveDocument.Type = ArchiveDocumentType.TestimonyAboutWedding; break; case 191: archiveDocument.Type = ArchiveDocumentType.AccountOpeningAgreement; break; case 192: archiveDocument.Type = ArchiveDocumentType.TreatyOfTelematics; break; case 201: archiveDocument.Type = ArchiveDocumentType.EmployeeWorkbook; break; case 202: archiveDocument.Type = ArchiveDocumentType.CaseOptacii; break; case 900: archiveDocument.Type = ArchiveDocumentType.Other; break; default: if (typeInstance != 0) throw new Exception("Incorrect Type during instantiating of Archive Document with ID = " + archiveDocument.Id); break; } archiveDocument.Serie = WebUtility.HtmlDecode( (string.IsNullOrWhiteSpace(serie) ? string.Empty : serie).Trim()); archiveDocument.Number = WebUtility.HtmlDecode( (string.IsNullOrWhiteSpace(number) ? string.Empty : number).Trim()); if (!string.IsNullOrWhiteSpace(issueDate)) { DateTime issueDateInstance; if (!DateTime.TryParse(issueDate, out issueDateInstance)) throw new Exception("Incorrect Issue Date during instantiating of Archive Document with ID = " + archiveDocument.Id); archiveDocument.IssueDate = issueDateInstance; } archiveDocument.Description = WebUtility.HtmlDecode( (string.IsNullOrWhiteSpace(description) ? string.Empty : description).Trim()); return archiveDocument; }