public string Post([FromBody] Course value) { if (!dbContext.Course.Any(course => course.Title.Equals(value.Title))) { Course course = new Course(); course.CourseId = value.CourseId; course.CreatorId = value.CreatorId; course.Title = value.Title; course.Description = value.Description; course.Date = value.Date; try { dbContext.Add(course); dbContext.SaveChanges(); return(JsonConvert.SerializeObject("Insert into Course OK - Remote DB")); } catch (Exception ex) { return(JsonConvert.SerializeObject(ex.InnerException.Message)); } } else { return(JsonConvert.SerializeObject("Course with the same title already exists - Remote DB")); } }
public string Post([FromBody] Student value) { if (!dbContext.Student.Any(user => user.Login.Equals(value.Login))) { Student student = new Student(); student.Id = value.Id; student.Login = value.Login; student.Password = value.Password; student.Name = value.Name; student.Mail = value.Mail; try { dbContext.Add(student); dbContext.SaveChanges(); return(JsonConvert.SerializeObject("Register successfully - Remote DB")); } catch (Exception e) { return(JsonConvert.SerializeObject(e.InnerException.Message)); } } else { return(JsonConvert.SerializeObject("User already exists - Remote DB")); } }
public string Post([FromBody] Member value) { Member member = new Member(); member.CourseId = value.CourseId; member.MemberId = value.MemberId; try { dbContext.Add(member); dbContext.SaveChanges(); return(JsonConvert.SerializeObject("Insert into Member OK - Remote DB")); } catch (Exception ex) { return(JsonConvert.SerializeObject(ex.InnerException.Message)); } }