TheHitchhiker
TheHitchhiker
CC#
Created by TheHitchhiker on 3/3/2023 in #help
❔ How to get hostname string ?
i need the hostname string in MappingProfile for automapper i have no access to HttpContext.Current.Request.Url.Host so how can i do that?
21 replies
CC#
Created by TheHitchhiker on 2/25/2023 in #help
❔ How to return image url in response ?
public class Picture : BaseEntity { public string Name { get; set; } public int? Width { get; set; } public int? Height { get; set; } public DateTime? AddedAt { get; set; } = DateTime.Now; } public class PictureResponse { public string URL { get; set; } public int? Height { get; set; } public int? Width { get; set; } public DateTime? AddedAt { get; set; } = DateTime.Now; } how to map imagename to complete path eg. api/images/someiamge.png ? or how should i even do that ?
2 replies
CC#
Created by TheHitchhiker on 2/8/2023 in #help
❔ Git - how to undo dumb stuff
im using visual studio 2022 and it gone like this : 1- i made a commit with wrong staged files (all of them) 2- i tried to revert commit 3- my changes to all files've gone and i'm left with aother unrevertable revert commit 4- i didnt push any commit yet how to remove last two commits and have my changes back?
9 replies
CC#
Created by TheHitchhiker on 11/11/2022 in #help
❔ How to parse a json response?
20 replies
CC#
Created by TheHitchhiker on 11/5/2022 in #help
How to refactor and unit test this method.
[HttpPost]
[Consumes(MediaTypeNames.Application.Json)] [ProducesResponseType(StatusCodes.Status201Created)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public IActionResult Post([FromBody] BlogRequest blogModel)
{
try
{
if (ModelState.IsValid)
{
var userId = User.Claims.Where(x => x.Type == "uid").FirstOrDefault()?.Value;
if(userId == null) return BadRequest(ModelState);
var blog = _mapper.Map<Blog>(blogModel);
blog.UserId = userId;
_unitOfWork.BlogRepository.Add(blog);
_unitOfWork.save();
return Created("~api/blogs", blogModel);
}
}
catch (Exception ex)
{
ModelState.AddModelError("AddBlog", ex.Message);
}
return BadRequest(ModelState);
}
[HttpPost]
[Consumes(MediaTypeNames.Application.Json)] [ProducesResponseType(StatusCodes.Status201Created)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public IActionResult Post([FromBody] BlogRequest blogModel)
{
try
{
if (ModelState.IsValid)
{
var userId = User.Claims.Where(x => x.Type == "uid").FirstOrDefault()?.Value;
if(userId == null) return BadRequest(ModelState);
var blog = _mapper.Map<Blog>(blogModel);
blog.UserId = userId;
_unitOfWork.BlogRepository.Add(blog);
_unitOfWork.save();
return Created("~api/blogs", blogModel);
}
}
catch (Exception ex)
{
ModelState.AddModelError("AddBlog", ex.Message);
}
return BadRequest(ModelState);
}
Hi guy i managed to mock the mapper & _unitOfWork but how should i mock authorized user's id ?
2 replies