public ActionResult Create(string id, Version model) { var company = Repository.GetById(id); if (company == null) { return(HttpNotFound()); } ViewBag.Title = company.CompanyName; if (ModelState.IsValid) { try { model.VersionId = Guid.NewGuid().ToString(); model.CreatedOn = _clock.UtcNow; company.Versions.Add(model); Repository.Update(company); return(RedirectToAction("CreateIpa", new { id, model.Number })); } catch { return(View(model)); } } return(View(model)); }
// // GET: /Admin/Version/Create public ActionResult Create(string id) { var company = Repository.GetById(id); if (company == null) { return(HttpNotFound()); } ViewBag.Title = company.CompanyName; var model = new Version(); model.WebsiteUrl = "https://api.taxihail.com/" + company.CompanyKey; return(View(model)); }
public static VersionViewModel CreateFrom(Company company, Version version) { return(new VersionViewModel { CompanyName = company.CompanyName, CompanyId = company.Id, ApplicationName = company.Application.AppName ?? company.CompanyName, ApkFilename = version.ApkFilename, ApkCallboxFilename = version.ApkCallboxFileName, IpaFilename = version.IpaFilename, IpaAppStoreFilename = version.IpaAppStoreFilename, ApkBlackBerryFilename = version.ApkBlackBerryFilename, BarFilename = version.BarFilename, WebsiteUrl = version.WebsiteUrl, VersionId = version.VersionId, Number = version.Number, CreatedOn = version.CreatedOn, }); }
public void Create_Post_creates_version_in_company() { // Arrange var ipa = new PostedFileStub("file.ipa"); var apk = new PostedFileStub("file.apk"); var model = new Version { Number = "12.34.56.78.90", WebsiteUrl = "http://website.url" }; // Act Sut.Create(CompanyId, model); // Assert var company = Repository.GetById(CompanyId); Assert.AreEqual(1, company.Versions.Count); Sut.CreateIpa(CompanyId, model.Number, ipa); Sut.CreateApk(CompanyId, model.Number, apk); var version = company.Versions[0]; Assert.AreEqual("12.34.56.78.90", version.Number); Assert.AreEqual("file.ipa", version.IpaFilename); Assert.AreEqual("file.apk", version.ApkFilename); Assert.AreEqual("http://website.url", version.WebsiteUrl); Assert.AreEqual(Clock.UtcNow, version.CreatedOn); // Test that files were saved string filename; Assert.IsTrue(Packages.Exists("file.ipa", out filename)); Assert.AreEqual("C:\\uploads\\file.ipa", filename); Assert.IsTrue(Packages.Exists("file.apk", out filename)); Assert.AreEqual("C:\\uploads\\file.apk", filename); }
public async Task <HttpResponseMessage> Post() { if (!Request.Content.IsMimeMultipartContent()) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "This request is not properly formatted")); } var provider = new MultipartFormDataStreamProvider(HostingEnvironment.MapPath("~/App_Data")); try { await Request.Content.ReadAsMultipartAsync(provider); var data = JsonConvert.DeserializeObject <CreateNewVersionRequest>(provider.FormData["data"]); if (string.IsNullOrEmpty(data.CompanyKey) || string.IsNullOrEmpty(data.VersionNumber) || string.IsNullOrEmpty(data.WebsiteUrl)) { DeleteTemporaryFiles(provider.FileData); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Missing parameters")); } var company = _repository.FirstOrDefault(x => x.CompanyKey == data.CompanyKey); if (company == null) { DeleteTemporaryFiles(provider.FileData); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Company does not exist")); } var existingVersion = company.Versions.FirstOrDefault(x => x.Number == data.VersionNumber); if (existingVersion != null) { company.Versions.Remove(existingVersion); _repository.Update(company); var packages = _packageManagerFactory.Invoke(company.Id, existingVersion.Number); packages.DeleteAll(); } var version = new Version { VersionId = Guid.NewGuid().ToString(), WebsiteUrl = data.WebsiteUrl, CreatedOn = _clock.UtcNow, Number = data.VersionNumber }; foreach (var file in provider.FileData) { if (IsAPK(file.Headers.ContentDisposition.FileName) && !IsApkBlackBerry(file.Headers.ContentDisposition.FileName) && !IsCallboxAPK(file.Headers.ContentDisposition.FileName)) { version.ApkFilename = file.Headers.ContentDisposition.FileName; } else if (IsAppStoreIpa(file.Headers.ContentDisposition.FileName)) { version.IpaAppStoreFilename = file.Headers.ContentDisposition.FileName; } else if ((!IsAppStoreIpa(file.Headers.ContentDisposition.FileName)) && (IsIpa(file.Headers.ContentDisposition.FileName))) { version.IpaFilename = file.Headers.ContentDisposition.FileName; } else if (IsCallboxAPK(file.Headers.ContentDisposition.FileName)) { version.ApkCallboxFileName = file.Headers.ContentDisposition.FileName; } else if (IsApkBlackBerry(file.Headers.ContentDisposition.FileName)) { version.ApkBlackBerryFilename = file.Headers.ContentDisposition.FileName; } else if (IsBar(file.Headers.ContentDisposition.FileName)) { version.BarFilename = file.Headers.ContentDisposition.FileName; } var path = ((PackageManager)_packageManagerFactory.Invoke(company.Id, data.VersionNumber)).GetFolderPath(); File.Move(file.LocalFileName, Path.Combine(path, file.Headers.ContentDisposition.FileName)); } company.Versions.Add(version); _repository.Update(company); //send email for the new version var appName = company.Application.AppName ?? company.CompanyName; var subject = appName + " version " + version.Number; var urlVersionDistribution = string.Format(Url.Link("Distribution", new { id = company.Id }) + "?versionId={0}", version.VersionId); var body = "Url of the version: " + urlVersionDistribution; WebMail.Send("*****@*****.**", subject, body); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } }