public bool Add(AdCreateModel entity) { #region Pictures Manipulation List <AdDetailPicture> pictures = new List <AdDetailPicture>(); if (entity.FilesAsListOfByteArray != null && entity.FilesAsListOfByteArray.Count > 0) { foreach (var file in entity.FilesAsListOfByteArray) { pictures.Add(new AdDetailPicture { File = file, CreatedBy = entity.CreatedBy, CreatedAt = entity.CreatedAt, ModifiedAt = entity.ModifiedAt, ModifiedBy = entity.ModifiedBy, }); } entity.MainPictureThumbnail = MagiskImageWrapper.MakeThumbnailImage(System.Convert.FromBase64String(entity.MainPictureFile)); } #endregion var ad = AdMapper.MapAdFromAdCreateModel(entity, pictures); return(_repository.Add(ad)); }
public HttpResponseMessage CreateNewAd(HttpRequestMessage request, Ad newAd) { return(GetHttpResponse(request, () => { HttpResponseMessage response = null; if (newAd.AdTitle == null || newAd.AdLocation == null || newAd.AdDescription == null) { return response = request.CreateResponse(HttpStatusCode.BadRequest, "Not all required fields have been filled"); } newAd.AccountId = User.Identity.GetUserId(); newAd.DateCreated = DateTime.Now; newAd.AdClosed = false; if (newAd.CategoryId == 0) { newAd.CategoryId = 4; } Ad account = adRepository.Add(newAd); response = request.CreateResponse <Ad>(HttpStatusCode.OK, account); return response; })); }
public async Task <bool> Create(AdModel ad) { try { AdModel _ad = new AdModel() { ano = ad.ano, Marca = ad.Marca, Modelo = ad.Modelo, Observacao = ad.Observacao, Quilometragem = ad.Quilometragem, Versao = ad.Versao }; await _adRepo.Add(_ad); int changed = await _adRepo.Commit(); if (changed > 0) { return(true); } return(false); } catch (AppException ex) { throw new AppException(ex.Message, ex.Code); } }
//[PrincipalPermission(SecurityAction.Demand, Role = SecurityValueObject.JonMtaaniAdminRole)] //[PrincipalPermission(SecurityAction.Demand, Name = SecurityValueObject.JonMtaaniUser)] public Ad CreateAd(Ad ad, string loginEmail) { return(ExecuteFaultHandledOperation(() => { IAdRepository adRepository = dataRepositoryFactory.GetDataRepository <IAdRepository>(); Ad newad = adRepository.Add(ad); return newad; })); }
public async Task <IResult> CreateAsync(AdForCreationDto adForCreation) { Guid memberId = UserIdentification.UserId; Ad ad = _mapper.Map <Ad>(adForCreation); ad.MemberId = memberId; ad.UserAndDateForCreation(); _adRepository.Add(ad); await _unitOfWork.CompleteAsync(); return(new SuccessResult(Messages.AdCreated, HttpStatusCode.Created)); }
//[PrincipalPermission(SecurityAction.Demand, Role = SecurityValueObject.JonMtaaniAdminRole)] //[PrincipalPermission(SecurityAction.Demand, Name = SecurityValueObject.JonMtaaniUser)] public Ad UpdateAd(Ad ad, string loginEmail) { return(ExecuteFaultHandledOperation(() => { IAdRepository adrepository = dataRepositoryFactory.GetDataRepository <IAdRepository>(); Ad updatedEntity = null; if (ad.AdId == 0) { updatedEntity = adrepository.Add(ad); } else { updatedEntity = adrepository.Update(ad); } return updatedEntity; })); }
public async Task <IActionResult> InsertAd(AdInsertModel model) { if (ModelState.IsValid) { var user = await userManager.GetUserAsync(HttpContext.User); Ad ad = new Ad { Product = model.Product, Description = model.Description, Price = model.Price, Category = model.Category, UnitsAvailable = model.UnitsAvailable, User = user, DateTime = DateTime.Now }; adRepository.Add(ad); return(RedirectToAction("ShowAds")); } return(View(model)); // retornar la vista del anuncio }