public void EditPersonal(QuestionSheetEdit data, int userId) { var user = context.Users.SingleOrDefault(x => x.Id == userId); if (user == null) { throw new ServiceException("User Not Found!"); } var sheet = context.QuestionSheets .SingleOrDefault(x => x.Id == data.Id && x.IsGlobal == false); if (sheet == null) { throw new ServiceException("Sheet Not Found!"); } if (sheet.UserId != user.Id) { throw new ServiceException("Sheet Does Not Belong To You!"); } sheet.Name = data.Name; sheet.Description = data.Description; sheet.Difficulty = data.Difficulty; sheet.Importance = data.Importance.Value; context.SaveChanges(); }
public IActionResult EditGlobal([FromBody] QuestionSheetEdit data) { try { SheetIndexWithScope result = questionSheetService.EditGlobal(data); return(Ok(result)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult EditPersonal([FromBody] QuestionSheetEdit data) { try { var userData = jwtService.ParseData(this.User); SheetIndexWithScope result = questionSheetService.EditPersonal(data, userData.UserId); return(Ok(result)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void EditGlobal(QuestionSheetEdit data) { var sheet = context.QuestionSheets .SingleOrDefault(x => x.Id == data.Id && x.IsGlobal == true); if (sheet == null) { throw new ServiceException("Sheet Not Found!"); } sheet.Name = data.Name; sheet.Description = data.Description; sheet.Difficulty = data.Difficulty; sheet.Importance = data.Importance.Value; context.SaveChanges(); }
public SheetIndexWithScope EditGlobal(QuestionSheetEdit data) { var sheet = context.QuestionSheets .SingleOrDefault(x => x.Id == data.Id && x.IsGlobal == true); if (sheet == null) { throw new ServiceException("Sheet Not Found!"); } sheet.Name = data.Name; sheet.Description = data.Description; sheet.Difficulty = data.Difficulty; sheet.Importance = data.Importance.Value; context.SaveChanges(); return(new SheetIndexWithScope { isGlobal = true, data = Mapper.Map <QuestionSheetChildIndex>(sheet), }); }