/// <summary> /// Uploads a file given a path string, and object representing a model, and a collection of files from a form. /// </summary> /// <param name="path"></param> /// <param name="obj"></param> /// <param name="formFiles"></param> /// <returns></returns> public async Task Upload(string path, object obj, IFormFileCollection formFiles) { var type = obj.GetType(); foreach (var f in formFiles) { IFormFile file = f; string temp = file.FileName; string uploads = Path.Combine(_hostingEnvironment.WebRootPath, path); string fileName = Guid.NewGuid() + Path.GetExtension(file.FileName); await using (FileStream fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } // OwnerBoardMemberVM Image Upload if (type == typeof(OwnerBoardMemberVM)) { OwnerBoardMemberVM obvm = (OwnerBoardMemberVM)obj; if (temp.Equals("")) { obvm.BoardMember.Image = "/" + path + "/" + "DefaultImage.png"; await _db.SaveChangesAsync(); } else { obvm.BoardMember.Image = "/" + path + "/" + fileName; await _db.SaveChangesAsync(); } _unitOfWork.BoardMember.Update(obvm.BoardMember); _unitOfWork.OwnerBoardMember.Update(obvm.OwnerBoardMember); } } }
public IActionResult OnGet(int?id) { OwnerBoardObj = new OwnerBoardMemberVM { OwnerBoardMember = new OwnerBoardMember(), Owner = new Models.Owner(), BoardMember = new BoardMember(), OwnerList = _unitOfWork.Owner.GetOwnerListForDropdown() }; if (id != null) { OwnerBoardObj.BoardMember = _unitOfWork.BoardMember.GetFirstOrDefault(b => b.Id == id); if (OwnerBoardObj == null) { return(NotFound()); } } return(Page()); }
public IActionResult OnGet(int?id) { OwnerBoardObj = new OwnerBoardMemberVM { OwnerBoardMember = new OwnerBoardMember(), Owner = new Models.Owner(), Lot = new Lot(), BoardMember = new BoardMember(), OwnerList = _unitOfWork.Owner.GetOwnerListForDropdown() }; BoardMemberList = _unitOfWork.BoardMember.GetAll().ToList(); OwnerList = _unitOfWork.Owner.GetAll().ToList(); OwnerBoardMemberList = _unitOfWork.OwnerBoardMember.GetAll().ToList(); LotOwners = _unitOfWork.Lot_Owner.GetAll().ToList(); if (id != null) { OwnerBoardObj.BoardMember = _unitOfWork.BoardMember.GetFirstOrDefault(b => b.Id == id); if (OwnerBoardObj == null) { return(NotFound()); } } foreach (var ob in OwnerBoardMemberList) { foreach (var lo in LotOwners) { if (ob.OwnerId == lo.OwnerId) { OwnerBoardObj.Lot = _unitOfWork.Lot.GetFirstOrDefault(l => l.Id == lo.LotId); } } } return(Page()); }