My service function:
public void Create(PostAddRequest model)
{
var featuredImageFile = "/Content/img/uploads/" + Guid.NewGuid() + "_" + model.FeaturedImage.FileName;
var post = new Post()
{
Title = model.Title,
CategoryId = model.CategoryId,
Content = model.Content,
Description = model.Description,
PersonId = HttpContext.Current.User.Identity.GetUserId(),
FeaturedImagePath = featuredImageFile,
CreatedOn = DateTime.UtcNow
};
model.FeaturedImage.SaveAs(Server.MapPath(featuredImageFile));
_unitOfWork.PostRepository.AddPost(post);
_unitOfWork.SaveChanges();
}
I'm getting an error saying: The name 'Server' does not exist in the current context
.
This error doesn't occur when I use Server.MapPath in a controller, but I'm using a 3 layer architecture and need to use it on a function outside a controller.