public ActionResult Register(CreateAttachmentDto input, HttpPostedFileBase newFile, int courseId) { if (ModelState.IsValid) { var fileName = $"{input.Title.Replace(" ", string.Empty)}_{input.EmployeeId}_{DateTime.Now.ToString("ddMMyyyyhhmmsstt")}.{newFile.FileName.Split('.')[1].Trim()}"; if (newFile != null && newFile.ContentLength > 0) { string root = @"C:\Attachments"; if (!Directory.Exists(root)) { Directory.CreateDirectory(root); } root = root + "\\" + fileName; newFile.SaveAs(root); } input.AttachmentFileName = fileName; var created = _repository.Create(input); if (created != null) { return(RedirectToAction("Index", "Attachments", new { employeeId = input.EmployeeId, courseId = courseId })); } } return(View(input)); }
public async Task <Response> SaveFiles(AttachmentRequest model) { ICollection <Attachment> attachmentDTO = await UploadAttachments(model); int result = await _attachmentRepository.Create(attachmentDTO); if (result > 0) { return(new Response { IsSuccess = true, Message = Messages.Created.ToString(), Result = result }); } else { return(new Response { IsSuccess = false, Message = Messages.NotCreated.ToString() }); } }
public bool Create(Attachment model) { return(rep.Create(model)); }