public CreateSelectResponse Create(CreateSelectRequest request) { var response = new CreateSelectResponse(); try { var select = request.MapTo<Select>(); DataContext.Selects.Add(select); if (request.ParentId != 0) { var parent = new Select { Id = request.ParentId }; DataContext.Selects.Attach(parent); select.Parent = parent; } if (request.ParentOptionId != 0) { var parentOption = new SelectOption { Id = request.ParentOptionId }; DataContext.SelectOptions.Attach(parentOption); select.ParentOption = parentOption; } DataContext.SaveChanges(); response.IsSuccess = true; response.Message = "Select has been added successfully"; } catch (DbUpdateException dbUpdateException) { response.Message = dbUpdateException.Message; } return response; }
public CreateSelectResponse Create(CreateSelectRequest request) { var response = new CreateSelectResponse(); try { var select = request.MapTo <Select>(); DataContext.Selects.Add(select); if (request.ParentId != 0) { var parent = new Select { Id = request.ParentId }; DataContext.Selects.Attach(parent); select.Parent = parent; } if (request.ParentOptionId != 0) { var parentOption = new SelectOption { Id = request.ParentOptionId }; DataContext.SelectOptions.Attach(parentOption); select.ParentOption = parentOption; } DataContext.SaveChanges(); response.IsSuccess = true; response.Message = "Select has been added successfully"; } catch (DbUpdateException dbUpdateException) { response.Message = dbUpdateException.Message; } return(response); }