public async Task <IActionResult> UpdateGate(string userId, string id, [FromForm] GateForCreateDto gateForUpdateDto) { var gateFromRepo = (await _db._GateRepository .GetAllAsync(p => p.Id == id, null, "Wallet")).SingleOrDefault(); if (gateFromRepo == null) { return(BadRequest("درگاهی وجود ندارد")); } if (gateFromRepo.Wallet.UserId == User.FindFirst(ClaimTypes.NameIdentifier).Value) { if (gateForUpdateDto.File != null) { if (gateForUpdateDto.File.Length > 0) { var uploadRes = await _uploadService.UploadFileToLocal( gateForUpdateDto.File, gateFromRepo.Wallet.UserId, _env.WebRootPath, $"{Request.Scheme ?? ""}://{Request.Host.Value ?? ""}{Request.PathBase.Value ?? ""}", "Files\\Gate" ); if (uploadRes.Status) { gateFromRepo.IconUrl = uploadRes.Url; } else { return(BadRequest(uploadRes.Message)); } } } var gate = _mapper.Map(gateForUpdateDto, gateFromRepo); // gate.Ip = await _utilities.GetDomainIpAsync(gate.WebsiteUrl); _db._GateRepository.Update(gate); if (await _db.SaveAcync() > 0) { return(NoContent()); } else { return(BadRequest("خطا در ثبت اطلاعات")); } } else { _logger.LogError($"کاربر {RouteData.Values["userId"]} قصد اپدیت به درگاه دیگری را دارد"); return(BadRequest("شما اجازه اپدیت درگاه کاربر دیگری را ندارید")); } }
public async Task <IActionResult> AddGate(string userId, [FromForm] GateForCreateDto gateForCreateDto) { var gateFromRepo = await _db.GateRepository .GetAsync(p => p.WebsiteUrl == gateForCreateDto.WebsiteUrl && p.Wallet.UserId == userId); if (gateFromRepo == null) { var gateForCreate = new Gate() { WalletId = gateForCreateDto.WalletId, IsDirect = false, IsActive = false }; if (gateForCreateDto.File != null) { if (gateForCreateDto.File.Length > 0) { var uploadRes = await _uploadService.UploadFileToLocal( gateForCreateDto.File, Guid.NewGuid().ToString(), _env.WebRootPath, $"{Request.Scheme ?? ""}://{Request.Host.Value ?? ""}{Request.PathBase.Value ?? ""}", "Files\\Gate" ); if (uploadRes.Status) { gateForCreate.IconUrl = uploadRes.Url; } else { return(BadRequest(uploadRes.Message)); } } else { gateForCreate.IconUrl = string.Format("{0}://{1}{2}/{3}", Request.Scheme, Request.Host.Value ?? "", Request.PathBase.Value ?? "", "wwwroot/Files/Pic/Logo/logo-gate.png"); } } else { gateForCreate.IconUrl = string.Format("{0}://{1}{2}/{3}", Request.Scheme, Request.Host.Value ?? "", Request.PathBase.Value ?? "", "wwwroot/Files/Pic/Logo/logo-gate.png"); } var gate = _mapper.Map(gateForCreateDto, gateForCreate); await _db.GateRepository.InsertAsync(gate); if (await _db.SaveAsync()) { var gateForReturn = _mapper.Map <GateForReturnDto>(gate); return(CreatedAtRoute("GetGate", new { v = HttpContext.GetRequestedApiVersion().ToString(), id = gate.Id, userId = userId }, gateForReturn)); } else { return(BadRequest("خطا در ثبت اطلاعات")); } } { return(BadRequest("این درگاه قبلا ثبت شده است")); } }