public void UploadDoc(string description, int customerId) { var files = Request.Files; if (files.Count == 0) { string sError = string.Format("No files received for customer {0}.", customerId); Log.Debug("{0}", sError); throw new Exception(sError); } // if OneUploadLimitation oLimitations = CurrentValues.Instance.GetUploadLimitations("AlertDocsController", "UploadDoc"); var oErrors = new List <string>(); for (int i = 0; i < files.Count; i++) { var file = Request.Files[i]; if (file == null) { string sError = string.Format("File #{0} for customer {1} is null.", i, customerId); Log.Debug("{0}", sError); oErrors.Add(sError); continue; } // if var body = new byte[file.InputStream.Length]; file.InputStream.Read(body, 0, file.ContentLength); if (string.IsNullOrWhiteSpace(oLimitations.DetectFileMimeType(body, file.FileName))) { string sError = string.Format("File #{0} for customer {1} cannot be accepted due to its MIME type.", i, customerId); Log.Debug("{0}", sError); oErrors.Add(sError); continue; } // if var customerRepo = ObjectFactory.GetInstance <CustomerRepository>(); var customer = customerRepo.Get(customerId); var doc = new MP_AlertDocument { BinaryBody = body, Customer = customer, Employee = _context.User, Description = description, UploadDate = DateTime.UtcNow, DocName = file.FileName }; _docRepo.SaveOrUpdate(doc); } if (oErrors.Count > 0) { throw new Exception(string.Join(" ", oErrors)); } }
public static AlertDoc FromDoc(MP_AlertDocument doc) { return(new AlertDoc { CreateDate = doc.UploadDate, Description = doc.Description, DocName = doc.DocName, EmployeeName = doc.Employee != null ? doc.Employee.Name : "system", Id = doc.Id }); }
} // IsOwner private LandRegistryDataModel GetLandRegistryData(out LandRegistryDB landRegistry) { Log.Debug("GetLandRegistryData begin cId {0} titleNumber {1}", this.customerID, this.titleNumber); //check cash var landRegistryLoad = new LandRegistryLoad(this.customerID); landRegistryLoad.Execute(); var customersLrs = landRegistryLoad.Result; var cache = customersLrs.Where(x => x.TitleNumber == this.titleNumber && ((x.RequestTypeEnum == LandRegistryRequestType.Res) || (x.RequestTypeEnum == LandRegistryRequestType.ResPoll)) && x.ResponseTypeEnum == LandRegistryResponseType.Success) .OrderByDescending(x => x.InsertDate) .FirstOrDefault(); if (cache != null) { var b = new LandRegistryModelBuilder(); var cacheModel = new LandRegistryDataModel { Request = cache.Request, Response = cache.Response, Res = b.BuildResModel(cache.Response), RequestType = cache.RequestTypeEnum, ResponseType = cache.ResponseTypeEnum, DataSource = LandRegistryDataSource.Cache }; if (!cache.Owners.Any()) { var owners = new List <LandRegistryOwnerDB>(); foreach (var owner in cacheModel.Res.Proprietorship.ProprietorshipParties) { var ownerDB = new LandRegistryOwnerDB { LandRegistryId = cache.Id, FirstName = owner.PrivateIndividualForename, LastName = owner.PrivateIndividualSurname, CompanyName = owner.CompanyName, CompanyRegistrationNumber = owner.CompanyRegistrationNumber, }; owners.Add(ownerDB); DB.ExecuteNonQuery("LandRegistryOwnerDBSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter("Tbl", ownerDB)); } cache.Owners = owners; } landRegistry = cache; return(cacheModel); } var isProd = CurrentValues.Instance.LandRegistryProd; ILandRegistryApi lr; if (isProd) { lr = new LandRegistryApi( CurrentValues.Instance.LandRegistryUserName, Encrypted.Decrypt(CurrentValues.Instance.LandRegistryPassword), CurrentValues.Instance.LandRegistryFilePath); } else { lr = new LandRegistryTestApi(); } LandRegistryDataModel model; if (this.titleNumber != null) { model = lr.Res(this.titleNumber, this.customerID); var customer = ObjectFactory.GetInstance <CustomerRepository>().Get(this.customerID); var lrDB = new LandRegistryDB { CustomerId = this.customerID, InsertDate = DateTime.UtcNow, TitleNumber = this.titleNumber, Request = model.Request, Response = model.Response, RequestType = model.RequestType.ToString(), ResponseType = model.ResponseType.ToString(), AttachmentPath = model.Attachment != null ? model.Attachment.FilePath : null }; int lrID = DB.ExecuteScalar <int>("LandRegistryDBSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter("Tbl", lrDB)); var owners = new List <LandRegistryOwnerDB>(); if (model.ResponseType == LandRegistryResponseType.Success && model.Res != null && model.Res.Proprietorship != null && model.Res.Proprietorship.ProprietorshipParties != null) { foreach (var owner in model.Res.Proprietorship.ProprietorshipParties) { var ownerDB = new LandRegistryOwnerDB { LandRegistryId = lrID, FirstName = owner.PrivateIndividualForename, LastName = owner.PrivateIndividualSurname, CompanyName = owner.CompanyName, CompanyRegistrationNumber = owner.CompanyRegistrationNumber, }; owners.Add(ownerDB); DB.ExecuteNonQuery("LandRegistryOwnerDBSave", CommandSpecies.StoredProcedure, DB.CreateTableParameter("Tbl", ownerDB)); } lrDB.Owners = owners; } landRegistry = lrDB; if (model.Attachment != null) { var fileRepo = ObjectFactory.GetInstance <NHibernateRepositoryBase <MP_AlertDocument> >(); var doc = new MP_AlertDocument { BinaryBody = model.Attachment.AttachmentContent, Customer = customer, Description = "LandRegistry", UploadDate = DateTime.UtcNow, DocName = model.Attachment.FileName }; fileRepo.SaveOrUpdate(doc); model.Attachment.AttachmentContent = null; } } else { landRegistry = null; model = new LandRegistryDataModel { Res = new LandRegistryResModel { Rejection = new LandRegistryRejectionModel { Reason = "Please perform enquiry first to retrieve title number" } }, ResponseType = LandRegistryResponseType.None }; } model.DataSource = LandRegistryDataSource.Api; return(model); } // GetLandRegistryData