public async Task <IActionResult> Create(CreateSosSignalInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var user = await this.userManager.GetUserAsync(this.User); try { await this.sosSignalService.CreateAsync(input, user.Id); } catch (Exception ex) { this.ModelState.AddModelError(string.Empty, ex.Message); return(this.View(input)); } // todo return to Clinic info return(this.Redirect("/SosSignal/All")); }
public async Task CreateAsync(CreateSosSignalInputModel input, string userId) { var extension = Path.GetExtension(input.Image.FileName); if (!this.allowedExtensions.Any(x => extension.EndsWith(x))) { throw new Exception($"Invalid image extension {extension}"); } var imageUrl = await this.cloudinaryService.UploadAsync(this.cloudinary, input.Image); var sosSignal = new SosSignal { UserId = userId, Name = input.Name, Location = input.Location, Description = input.Description, ImageUrl = imageUrl, }; await this.sosSignalsRepository.AddAsync(sosSignal); await this.sosSignalsRepository.SaveChangesAsync(); }