public BaseResponseModel Post(UpdateExamDetailsRequestModel model) { if (User.Identity?.Name == null) { // Not logged in return(ErrorCodes.CreateSimpleResponse(ErrorCodes.NotLoggedIn)); } var exam = _examServices.GetObject(model.Id); if (exam == null) { // Exam not exists return(ErrorCodes.CreateSimpleResponse(ErrorCodes.ExamNotExist)); } if (exam.Creator != User.Identity?.Name) { return(ErrorCodes.CreateSimpleResponse(ErrorCodes.ExamNotPermitToEdit)); } var duration = model.Duration.Hour * 3600 + model.Duration.Minute * 60 + model.Duration.Second; exam.Name = model.Name; exam.Description = model.Description; exam.Duration = duration; exam.StartTime = model.StartTime; exam.OpenBook = model.OpenBook; exam.MaximumTakersNum = model.MaximumTakersNum; _examServices.SaveObject(exam); return(ErrorCodes.CreateSimpleResponse(ErrorCodes.Success)); }
public BaseResponseModel Post(CreateExamRequestModel model) { if (User.Identity?.Name == null) { return(ErrorCodes.CreateSimpleResponse(ErrorCodes.NotLoggedIn)); } try { // convert the duration var duration = model.Duration.Hour * 3600 + model.Duration.Minute * 60 + model.Duration.Second; var a = new Data.Entities.Exam() { Creator = User.Identity?.Name, Description = model.Description, Duration = duration, Name = model.ExamTitle, StartTime = model.StartTime, MaximumTakersNum = model.MaxTakers, OpenBook = model.OpenBook }; _services.SaveObject(a); return(ErrorCodes.CreateSimpleResponse(ErrorCodes.Success)); } catch { return(ErrorCodes.CreateSimpleResponse(ErrorCodes.UnknownError)); } }