public IActionResult AddItem([FromBody] Item model) { if (model == null) { return(BadRequest()); } System.Security.Claims.Claim userIdClaim = User.Claims.Single(c => c.Type == "id"); var user = _userManager.Users.FirstOrDefault(x => x.Id.ToString() == userIdClaim.Value); var item = new Item { ItemName = model.ItemName, UserId = user.Id, CreatedOnDate = DateTime.UtcNow, CanBeBorrowed = model.CanBeBorrowed, LentOut = model.LentOut, LentTo = model.LentTo, ImageFileContent = model.ImageFileContent, ImageFileType = "URL" }; _itemData.AddItem(item); _itemData.Commit(); return(Ok(item)); }
public ActionResult CreateItem(ItemDTO obj, IFormFile files1, IFormFile files2, IFormFile files3, IFormFile files4, int id) { var itemcategoryid = HttpContext.Request.Form["ItemCategoryId"].ToString(); obj.ItemCategoryId = Convert.ToInt32(itemcategoryid); if (ModelState.IsValid) { //First Image /////////////////////////////////////////////////// if (files1 != null) { var filepath = Path.GetTempFileName(); string filename = ContentDispositionHeaderValue.Parse(files1.ContentDisposition).FileName.Trim('"'); filename = this.EnsureFilename(filename); using (FileStream filestream = System.IO.File.Create(this.Getpath(filename, id, obj))) { files1.CopyToAsync(filestream); obj.ImageUrl1 = "\\" + obj.SignUpId + "\\" + obj.ItemName + "\\" + filename; } } //Second Image //////////////////////////////////////////////// if (files2 != null) { var filepath = Path.GetTempFileName(); string filename = ContentDispositionHeaderValue.Parse(files2.ContentDisposition).FileName.Trim('"'); filename = this.EnsureFilename(filename); using (FileStream filestream = System.IO.File.Create(this.Getpath(filename, id, obj))) { files2.CopyToAsync(filestream); obj.ImageUrl2 = "\\" + obj.SignUpId + "\\" + obj.ItemName + "\\" + filename; } } //Third image ///////////////////////////////////////////////// if (files3 != null) { var filepath = Path.GetTempFileName(); string filename = ContentDispositionHeaderValue.Parse(files3.ContentDisposition).FileName.Trim('"'); filename = this.EnsureFilename(filename); using (FileStream filestream = System.IO.File.Create(this.Getpath(filename, id, obj))) { files3.CopyToAsync(filestream); obj.ImageUrl3 = "\\" + obj.SignUpId + "\\" + obj.ItemName + "\\" + filename; } } //Fourth Image /////////////////////////////////////////////// if (files4 != null) { var filepath = Path.GetTempFileName(); string filename = ContentDispositionHeaderValue.Parse(files4.ContentDisposition).FileName.Trim('"'); filename = this.EnsureFilename(filename); using (FileStream filestream = System.IO.File.Create(this.Getpath(filename, id, obj))) { files4.CopyToAsync(filestream); obj.ImageUrl4 = "\\" + obj.SignUpId + "\\" + obj.ItemName + "\\" + filename; } } //foreach (IFormFile item in files) //{ // string filename = ContentDispositionHeaderValue.Parse(item.ContentDisposition).FileName.Trim('"'); // filename = this.EnsureFilename(filename); // using (FileStream filestream = System.IO.File.Create(this.Getpath(filename, id, obj))) // { // item.CopyToAsync(filestream); // obj.ImageUrl1 = filename; // } //} //Second Image /////////////////////////////////////////////////// //foreach (IFormFile item in files) //{ // string filename = ContentDispositionHeaderValue.Parse(item.ContentDisposition).FileName.Trim('"'); // //filename = this.EnsureFilename(filename); // using (FileStream filestream = System.IO.File.Create(this.Getpath(filename, id, obj))) // { // item.CopyToAsync(filestream); // } // obj.ImageUrl2 = filename; //} //// Third Image /////////////////////////////////////////////////// //foreach (IFormFile item in files) //{ // string filename = ContentDispositionHeaderValue.Parse(item.ContentDisposition).FileName.Trim('"'); // //filename = this.EnsureFilename(filename); // using (FileStream filestream = System.IO.File.Create(this.Getpath(filename, id, obj))) // { // item.CopyToAsync(filestream); // } // obj.ImageUrl3 = filename; //} ////Fourth Image ///////////////////////////////////////////////// //foreach (IFormFile item in files) //{ // string filename = ContentDispositionHeaderValue.Parse(item.ContentDisposition).FileName.Trim('"'); // filename = this.EnsureFilename(filename); // using (FileStream filestream = System.IO.File.Create(this.Getpath(filename, id,obj))) // { // item.CopyToAsync(filestream); // } // obj.ImageUrl4 = filename; //} try { _itemData.AddItem(obj); return(RedirectToAction("ItemList", "Item", new { id = id })); } catch (Exception) { throw; } } return(View()); }