public async Task <ObjectResult> Create([Bind("Title,Image, CustomerIds, TagIds, SharingDescription, Summary")] Solution solution) { if (solution.Image == null) { ModelState.AddModelError(nameof(solution.Image), "The Image field is required."); } else { if (!(new[] { ".png", ".jpg", ".jpeg" }).Contains(Path.GetExtension(solution.Image.FileName)?.ToLower())) { ModelState.AddModelError(nameof(solution.Image), "Invalid image type, only png and jpg images are allowed"); } if (solution.Image.Length < 1) { ModelState.AddModelError(nameof(solution.Image), "Filesize too small"); } } if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } if (solution.Image != null) { solution.PhotoPath = await _uploadService.Upload(solution.Image, "/images/uploads/solutions"); } solution.SolutionTags = solution.TagIds?.Select(tagId => new SolutionTag { Solution = solution, TagId = tagId }).ToList(); solution.CustomerSolutions = solution.CustomerIds?.Select(customerId => new CustomerSolution { CustomerId = customerId, Solution = solution }).ToList(); solution.LastModified = DateTime.UtcNow; solution.Date = DateTime.UtcNow; solution.Language = "nl"; try { await _solutionRepository.Create(solution); return(new ObjectResult(solution.Id)); } catch (DbUpdateException) { return(new ObjectResult(null) { StatusCode = StatusCodes.Status500InternalServerError, }); } }
public void Save(Solution solution) { var problem = _problemRepository.Get(solution.ProblemId); var adapt = new Service.Storage.Entities.Solution { CreatedOn = solution.SendTime, Input = solution.Input, UserId = solution.UserId, TestResult = solution.Result.Adapt <Service.Storage.ExtraModels.TestResults>(), Problem = problem }; _solutionRepository.Create(adapt); }
public IActionResult Add([FromForm] Solution solution) { if (ModelState.IsValid) { var solutionToBeInserted = new Solution { SolutionId = Guid.NewGuid(), ProblemId = solution.ProblemId, Author = solution.Author, DateAdded = DateTime.Now, Content = solution.Content, Name = solution.Name, Visible = solution.Visible }; _solutionRepository.Create(solutionToBeInserted); _solutionRepository.Save(); return(RedirectToAction(nameof(ProblemSolution), new { id = solution.ProblemId })); } return(View()); }
public bool Create(Domain.Solution entity) { entity.OrganizationId = this._appContext.OrganizationId; return(_solutionRepository.Create(entity)); }