public async Task <IActionResult> OnUpdateAsync([FromForm] Courses.Fields fields) { if (fields.ImageUrl != null) { string path = Path.Combine("wwwroot/Course/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string img = utility.Generate_Unique_Number() + fields.ImageUrl.FileName; var file = Path.Combine("wwwroot/Course/" + img); using (var fileStream = new FileStream(file, FileMode.Create)) { await fields.ImageUrl.CopyToAsync(fileStream); } //بررسی اینکه از قبل فایل موجود هستش حذف شود. //string fullPath = Path.Combine(_environment.ContentRootPath, "wwwroot/Course/" + NamePicture); //if (System.IO.File.Exists(fullPath)) //{ // System.IO.File.Delete(fullPath); //} fields.filename = img; } else if (fields.ImageUrl == null) { fields.filename = ""; } await tblCourses.Update(fields); return(Ok()); }
public async Task <IEnumerable <Courses.Select> > SelectCourse(Courses.Fields fieldList) { List <Courses.Select> course = new List <Courses.Select>(); SqlCommand commnd = new SqlCommand(); var dicData = new Dictionary <string, string>(); dicData[Dictionary_Fields.CourseId] = fieldList.CourseId; dicData[Dictionary_Fields.StatementType] = Dictionary_Fields.SelectCourse; course = await hlp.DataReaderMapToList <Courses.Select>(commnd, Pro, dicData); return(course); }
public async Task Insert(Courses.Fields fieldList) { SqlCommand commnd = new SqlCommand(); var dicData = new Dictionary <string, object>(); dicData[Dictionary_Fields.Title] = fieldList.Title; dicData[Dictionary_Fields.ImageUrl] = fieldList.filename; dicData[Dictionary_Fields.Price] = StringExtensions.RemovePoint(fieldList.Price); dicData[Dictionary_Fields.Descriptions] = fieldList.Descriptions; dicData[Dictionary_Fields.CourseTime] = fieldList.CourseTime; dicData[Dictionary_Fields.IsActive] = fieldList.IsActive; dicData[Dictionary_Fields.StatementType] = Dictionary_Fields.Insert; await hlp.Operations(commnd, Pro, dicData); await commnd.ExecuteNonQueryAsync(); }
public async Task <IActionResult> SelectCourse([FromQuery] Courses.Fields fields) { return(new JsonResult(await tblCourses.SelectCourse(fields))); }