public App GenerateTempApp(UploadDTO uploadDTO) { return(new App() { Name = uploadDTO.AppName, Genre = uploadDTO.Genre, LastUpdate = uploadDTO.LastUpdate, AppBrand = uploadDTO.AppBrand }); }
//Projects the user information contained into uploadDTO over a new User object public User UserDotUploadDTO(UploadDTO uploadDTO) { User newUser = GenerateNewUserFromDTO(uploadDTO); if (GenerateControlIfDuplicateUserOnDB(newUser) == null) { newUser = _userRepository.AddEntityReturned(newUser); _playStoreDBContext.SaveChanges(); } return(GenerateControlIfDuplicateUserOnDB(newUser)); }
public User GenerateNewUserFromDTO(UploadDTO uploadDTO = null, DownloadDTO downloadDTO = null) { if (uploadDTO == null && downloadDTO == null) { throw new ArgumentNullException(); } return(new User() { Name = uploadDTO.DeveloperName, Surname = uploadDTO.DeveloperSurname, Email = uploadDTO.Email }); }
public void AppDotUploadDTO(UploadDTO uploadDTO) { var tempApp = GenerateTempApp(uploadDTO); App checkApp = _playStoreDBContext.Apps.Where(x => x.LastUpdate == tempApp.LastUpdate).FirstOrDefault(); if (checkApp == null) { //Add to Apps App tempTempApp = _appRepository.AddEntityReturned(tempApp); //tempApp = tempTempApp; _playStoreDBContext.SaveChanges(); } tempApp = _playStoreDBContext.Apps.Where(x => x.LastUpdate == tempApp.LastUpdate).FirstOrDefault(); }
public void SaveUpload(int id, UploadDTO file) { var currentProject = _projectRepo.Get(id).FirstOrDefault(); // check if current project is null first if (currentProject != null) { var newUpload = new Upload() { Name = file.Name, Url = file.Url, Project = currentProject, Type = (Upload.Classification)Enum.Parse(typeof(Upload.Classification), file.Type) }; _uploadRepo.Add(newUpload); _uploadRepo.SaveChanges(); } }
public async Task <IHttpActionResult> Post(int id) { var formData = await this.ReadFile(); var file = formData.Files[0]; var dst = HttpContext.Current.Server.MapPath("~/Public/" + file.RemoteFileName); file.FileInfo.MoveTo(dst); var type = formData.FormData["type"][0]; var dto = new UploadDTO() { Name = file.RemoteFileName, Url = Url.Content("~/Public/" + file.RemoteFileName), Type = type }; _uploadServ.SaveUpload(id, dto); return(Ok()); }
// PUT: api/Articles/PutArticle/:articleid public async Task <IActionResult> PutArticle([FromBody] UploadDTO model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (model.idarticulo <= 0) { return(BadRequest()); } var articulo = await _context.Articles.FirstOrDefaultAsync(a => a.idarticulo == model.idarticulo); if (articulo == null) { return(NotFound()); } articulo.idcategoria = model.idcategoria; articulo.idempresa = model.idempresa; articulo.codigo = model.codigo; articulo.nombre = model.nombre; articulo.precio_venta = model.precio_venta; articulo.stock = model.stock; articulo.descripcion = model.descripcion; articulo.imagen = model.imagen; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { // Guardar Excepción return(BadRequest()); } return(Ok()); }
public void AddUpload(UploadDTO uploadDTO) { //check sul valore nullo ArgumentNullException //*************************************************** var tempUser = new User() { Name = uploadDTO.DeveloperName, Surname = uploadDTO.DeveloperSurname, Email = uploadDTO.Email }; User checkUser = _playStoreDBContext.Users.Where(x => x.Email == tempUser.Email).FirstOrDefault(); if (checkUser == null) { //Add to Users User tempTempUser = _userRepository.AddEntityReturned(tempUser); //tempUser = tempTempUser; _playStoreDBContext.SaveChanges(); } tempUser = _playStoreDBContext.Users.Where(x => x.Email == tempUser.Email).FirstOrDefault(); //***************************************************** var tempApp = new App() { Name = uploadDTO.AppName, Genre = uploadDTO.Genre, LastUpdate = uploadDTO.LastUpdate, AppBrand = uploadDTO.AppBrand }; App checkApp = _playStoreDBContext.Apps.Where(x => x.LastUpdate == tempApp.LastUpdate).FirstOrDefault(); if (checkApp == null) { //Add to Apps App tempTempApp = _appRepository.AddEntityReturned(tempApp); //tempApp = tempTempApp; _playStoreDBContext.SaveChanges(); } tempApp = _playStoreDBContext.Apps.Where(x => x.LastUpdate == tempApp.LastUpdate).FirstOrDefault(); //***************************************************** var tempCompatibility = new Compatibilities() { DeviceType = uploadDTO.DeviceType }; //Add to Compatibilities Compatibilities tempTempCompatibility = _compatibilityRepository.AddEntityReturned(tempCompatibility); tempCompatibility = tempTempCompatibility; _playStoreDBContext.SaveChanges(); //***************************************************** var tempPrice = new Prices() { Currency = uploadDTO.Currency, Value = uploadDTO.Value }; //Add to Prices Prices tempTempPrice = _priceRepository.AddEntityReturned(tempPrice); tempPrice = tempTempPrice; _playStoreDBContext.SaveChanges(); //***************************************************** var tempUserApp = new UserApp() { UsersId = tempUser.Id, AppsId = tempApp.Id }; UserApp checkUserApp = _playStoreDBContext.UserApp.Where(x => x.UsersId == tempUserApp.UsersId && x.AppsId == tempUserApp.AppsId).FirstOrDefault(); if (checkUserApp == null) { //Add to UserApp UserApp tempTempUserApp = _userAppRepository.AddEntityReturned(tempUserApp); //tempUserApp=tempTempUserApp; _playStoreDBContext.SaveChanges(); } tempUserApp = _playStoreDBContext.UserApp.Where(x => x.UsersId == tempUserApp.UsersId && x.AppsId == tempUserApp.AppsId).FirstOrDefault(); //***************************************************** var tempUploads = new Uploads() { UsersId = tempUser.Id, UserAppId = tempUserApp.Id, Accepted = uploadDTO.Accepted, Update = uploadDTO.Update }; //Add to Uploads Uploads tempTempUploads = _uploadRepository.AddEntityReturned( tempUploads ); tempUploads = tempTempUploads; _playStoreDBContext.SaveChanges(); //***************************************************** }
public VerifyUploadResult VerifyUpload(UploadDTO dto, int maxPhotoChars, int minPhotoChars, double minimumImageSizeMB, double maximumImageSizeMB, List <string> validExtensions, int ingredientNameMaxChars, int ingredientNameMinChars, double maxIngredientPrice, int descriptionMaxChars, int descriptionMinChars, List <string> validCategories, List <string> validPriceUnits, int validTimeBufferMinutes, int maxRating, int minRating) { var validPhotoPath = StringUtilityService.CheckLength(dto.ImagePath, maxPhotoChars, minPhotoChars); if (!validPhotoPath) { return(new VerifyUploadResult(Constants.ImagePathInvalidMessage, false)); } var sizeMB = dto.ImageSize * Constants.ToMBConversionFactor; var validSize = sizeMB >= minimumImageSizeMB && sizeMB <= maximumImageSizeMB; if (!validSize) { return(new VerifyUploadResult(Constants.ImageNotWithinSizeMessage, false)); } var fileExtension = "." + dto.ImagePath.Split('.').Last(); var validExt = false; foreach (var ext in validExtensions) { validExt = validExt || (fileExtension.ToLower().Equals(ext.ToLower())); } if (!validExt) { return(new VerifyUploadResult(Constants.ExtensionNotValidMessage, false)); } var validCat = false; foreach (var cat in validCategories) { validCat = validCat || (dto.Category.ToLower().Equals(cat.ToLower())); } if (!validCat) { return(new VerifyUploadResult(Constants.CategoryNotValidMessage, false)); } if (!dto.Name.Equals(Constants.NoValueString)) { var validNameLength = StringUtilityService.CheckLength(dto.Name, ingredientNameMaxChars, ingredientNameMinChars); if (!validNameLength) { return(new VerifyUploadResult(Constants.IngredientNameLengthInvalidMessage, false)); } } if (!dto.Price.Equals(Constants.NoValueDouble)) { var validPrice = dto.Price > Constants.NoValueDouble && dto.Price <= maxIngredientPrice; if (!validPrice) { return(new VerifyUploadResult(Constants.PriceInvalidMessage, false)); } } if (!dto.Description.Equals(Constants.NoValueString)) { var validDescriptionLength = StringUtilityService.CheckLength(dto.Description, descriptionMaxChars, descriptionMinChars); if (!validDescriptionLength) { return(new VerifyUploadResult(Constants.DescriptionLengthInvalidMessage, false)); } } if (!dto.PriceUnit.Equals(Constants.NoValueString)) { var validUnit = false; foreach (var unit in validPriceUnits) { validUnit = validUnit || (dto.PriceUnit.ToLower().Equals(unit.ToLower())); } if (!validUnit) { return(new VerifyUploadResult(Constants.PriceUnitNotValidMessage, false)); } } if (!dto.Time.Equals(Constants.NoValueDatetime)) { var validTime = (DateTime.Now - dto.Time).TotalMinutes <= validTimeBufferMinutes; if (!validTime) { return(new VerifyUploadResult(Constants.TimeNotValidMessage, false)); } } if (!dto.Rating.Equals(Constants.NoValueInt)) { var validRating = dto.Rating >= minRating && dto.Rating <= maxRating; if (!validRating) { return(new VerifyUploadResult(Constants.InvalidRatingMessage, false)); } } return(new VerifyUploadResult(Constants.NoValueString, true)); }
public async Task <Result <bool> > CreateUploadAsync(UploadPost post, int failureCount) { var result = false; // Escape condition for recursive call if exception is thrown. if (failureCount >= Constants.OperationRetry) { return(SystemUtilityService.CreateResult(Constants.UploadCreationErrorMessage, result, true)); } try { if (!await _userManagementService.CheckUserExistenceAsync(post.Username).ConfigureAwait(false)) { // Log the fact user was invalid. await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString), Constants.CreateUploadOperation, post.Username, post.IPAddress, Constants.UploadUserDNESystemMessage).ConfigureAwait(false); return(SystemUtilityService.CreateResult(Constants.UploadUserDNEUserMessage, result, false)); } var latLong = LocationUtilityService.GetImageLatitudeAndLongitude(post.Image); var latitude = latLong.Item1; var longitude = latLong.Item2; var withinScope = LocationUtilityService.CheckLocationWithinPolygon(latitude, longitude, Constants.CurrentScopePolygon); if (!withinScope) { // Log the fact that scope was violated. await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString), Constants.CreateUploadOperation, post.Username, post.IPAddress, Constants.ImageNotWithinScopeSystemMessage).ConfigureAwait(false); return(SystemUtilityService.CreateResult(Constants.ImageNotWithinScopeUserMessage, result, false)); } var storeID = await _storeService.FindStoreAsync(latitude, longitude).ConfigureAwait(false); if (storeID == Constants.NoStoreFoundCode) { // Log the fact that scope was violated. await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString), Constants.CreateUploadOperation, post.Username, post.IPAddress, Constants.NoStoreFoundSystemMessage).ConfigureAwait(false); return(SystemUtilityService.CreateResult(Constants.NoStoreFoundUserMessage, result, false)); } var imagePath = Constants.PhotoFolder + "\\" + post.Username + "_" + TimeUtilityService.CurrentUnixTime() + post.FileExtension; var uploadDTO = new UploadDTO(imagePath, post.Image, post.Category, post.Name, (DateTime)post.PostTime, post.Username, post.Description, post.Rating, post.Price, post.PriceUnit, post.ImageSize); var verification = _uploadService.VerifyUpload(uploadDTO, Constants.MaximumPhotoCharacters, Constants.MinimumPhotoCharacters, Constants.MinimumImageSizeMB, Constants.MaximumImageSizeMB, Constants.ValidImageExtensions, Constants.IngredientNameMaximumCharacters, Constants.IngredientNameMinimumCharacters, Constants.MaximumIngredientPrice, Constants.DescriptionMaximumCharacters, Constants.DescriptionMinimumCharacters, Constants.ExogredientCategories, Constants.ExogredientPriceUnits, Constants.ValidTimeBufferMinutes, Constants.MaximumRating, Constants.MinimumRating); if (!verification.VerificationStatus) { // Log the fact that scope was violated. await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString), Constants.CreateUploadOperation, post.Username, post.IPAddress, Constants.UploadNotValidSystemMessage).ConfigureAwait(false); return(SystemUtilityService.CreateResult(verification.Message, result, false)); } Directory.CreateDirectory(Constants.PhotoFolder); post.Image.Save(imagePath); var uploadRecord = new UploadRecord(post.PostTime, post.Username, storeID, post.Description, post.Rating.ToString(), imagePath, post.Price, post.PriceUnit, post.Name, Constants.NoValueInt, Constants.NoValueInt, Constants.NotInProgressStatus, post.Category); await _uploadService.CreateUploadAsync(uploadRecord).ConfigureAwait(false); result = true; } catch (Exception ex) { // Log exception. await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString), Constants.CreateUploadOperation, post.Username, post.IPAddress, ex.ToString()).ConfigureAwait(false); // Recursively retry the operation until the maximum amount of retries is reached. await CreateUploadAsync(post, ++failureCount).ConfigureAwait(false); } // Log the fact that the operation was successful. await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString), Constants.CreateUploadOperation, post.Username, post.IPAddress).ConfigureAwait(false); return(SystemUtilityService.CreateResult(Constants.UploadCreationSuccessMessage, result, false)); }